Skip to content

Commit 00c828b

Browse files
committed
chore(phpstan): set level 7 and fix related issues
1 parent fbfa656 commit 00c828b

32 files changed

+218
-169
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 7
33
reportUnmatchedIgnoredErrors: false
44
paths:
55
- src

src/Api/Issue/GithubIssueApi.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace App\Api\Issue;
44

55
use App\Model\Repository;
6-
use App\Service\TaskHandler\CloseDraftHandler;
7-
use App\Service\TaskHandler\CloseStaleIssuesHandler;
86
use Github\Api\Issue;
97
use Github\Api\Issue\Comments;
108
use Github\Api\Search;
@@ -21,7 +19,7 @@ public function __construct(
2119
) {
2220
}
2321

24-
public function open(Repository $repository, string $title, string $body, array $labels)
22+
public function open(Repository $repository, string $title, string $body, array $labels): void
2523
{
2624
$params = [
2725
'title' => $title,
@@ -43,26 +41,23 @@ public function open(Repository $repository, string $title, string $body, array
4341
}
4442
}
4543

46-
public function lastCommentWasMadeByBot(Repository $repository, $number): bool
44+
public function lastCommentWasMadeByBot(Repository $repository, int $number): bool
4745
{
4846
$allComments = $this->issueCommentApi->all($repository->getVendor(), $repository->getName(), $number, ['per_page' => 100]);
4947
$lastComment = $allComments[count($allComments) - 1] ?? [];
5048

5149
return $this->botUsername === ($lastComment['user']['login'] ?? null);
5250
}
5351

54-
public function show(Repository $repository, $issueNumber): array
52+
/**
53+
* @return array<string, mixed>
54+
*/
55+
public function show(Repository $repository, int $issueNumber): array
5556
{
5657
return $this->issueApi->show($repository->getVendor(), $repository->getName(), $issueNumber);
5758
}
5859

59-
/**
60-
* Close an issue and mark it as "not_planned".
61-
*
62-
* @see CloseDraftHandler
63-
* @see CloseStaleIssuesHandler
64-
*/
65-
public function close(Repository $repository, $issueNumber): void
60+
public function close(Repository $repository, int $issueNumber): void
6661
{
6762
$this->issueApi->update(
6863
$repository->getVendor(),
@@ -78,7 +73,7 @@ public function close(Repository $repository, $issueNumber): void
7873
/**
7974
* This will comment on both Issues and Pull Requests.
8075
*/
81-
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
76+
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void
8277
{
8378
$this->issueCommentApi->create(
8479
$repository->getVendor(),
@@ -88,6 +83,9 @@ public function commentOnIssue(Repository $repository, $issueNumber, string $com
8883
);
8984
}
9085

86+
/**
87+
* @return array<int, array<string, mixed>>
88+
*/
9189
public function findStaleIssues(Repository $repository, \DateTimeImmutable $noUpdateAfter): iterable
9290
{
9391
return $this->resultPager->fetchAllLazy($this->searchApi, 'issues', [

src/Api/Issue/IssueApi.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ interface IssueApi
1414
{
1515
/**
1616
* Open new issue or update existing issue.
17+
*
18+
* @param array<string> $labels
1719
*/
18-
public function open(Repository $repository, string $title, string $body, array $labels);
20+
public function open(Repository $repository, string $title, string $body, array $labels): void;
1921

20-
public function show(Repository $repository, $issueNumber): array;
22+
/**
23+
* @return array<string, mixed>
24+
*/
25+
public function show(Repository $repository, int $issueNumber): array;
2126

22-
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody);
27+
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void;
2328

24-
public function lastCommentWasMadeByBot(Repository $repository, $number): bool;
29+
public function lastCommentWasMadeByBot(Repository $repository, int $number): bool;
2530

31+
/**
32+
* @return iterable<array<string, mixed>>
33+
*/
2634
public function findStaleIssues(Repository $repository, \DateTimeImmutable $noUpdateAfter): iterable;
2735

2836
/**
2937
* Close an issue and mark it as "not_planned".
3038
*/
31-
public function close(Repository $repository, $issueNumber): void;
39+
public function close(Repository $repository, int $issueNumber): void;
3240
}

src/Api/Issue/NullIssueApi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
class NullIssueApi implements IssueApi
88
{
9-
public function open(Repository $repository, string $title, string $body, array $labels)
9+
public function open(Repository $repository, string $title, string $body, array $labels): void
1010
{
1111
}
1212

13-
public function show(Repository $repository, $issueNumber): array
13+
public function show(Repository $repository, int $issueNumber): array
1414
{
1515
return [];
1616
}
1717

18-
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
18+
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void
1919
{
2020
}
2121

22-
public function lastCommentWasMadeByBot(Repository $repository, $number): bool
22+
public function lastCommentWasMadeByBot(Repository $repository, int $number): bool
2323
{
2424
return false;
2525
}
@@ -29,7 +29,7 @@ public function findStaleIssues(Repository $repository, \DateTimeImmutable $noUp
2929
return [];
3030
}
3131

32-
public function close(Repository $repository, $issueNumber): void
32+
public function close(Repository $repository, int $issueNumber): void
3333
{
3434
}
3535
}

src/Api/Label/GithubLabelApi.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GithubLabelApi implements LabelApi
1818
/**
1919
* In memory cache for specific issues.
2020
*
21-
* @var array<array-key, array<array-key, bool>>
21+
* @var array<string, array<string, bool>>
2222
*/
2323
private array $labelCache = [];
2424

@@ -30,7 +30,10 @@ public function __construct(
3030
) {
3131
}
3232

33-
public function getIssueLabels($issueNumber, Repository $repository): array
33+
/**
34+
* @return array|string[]
35+
*/
36+
public function getIssueLabels(int $issueNumber, Repository $repository): array
3437
{
3538
$key = $this->getCacheKey($issueNumber, $repository);
3639
if (!isset($this->labelCache[$key])) {
@@ -54,12 +57,12 @@ public function getIssueLabels($issueNumber, Repository $repository): array
5457
return $labels;
5558
}
5659

57-
public function addIssueLabel($issueNumber, string $label, Repository $repository)
60+
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void
5861
{
5962
$this->addIssueLabels($issueNumber, [$label], $repository);
6063
}
6164

62-
public function removeIssueLabel($issueNumber, string $label, Repository $repository)
65+
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void
6366
{
6467
$key = $this->getCacheKey($issueNumber, $repository);
6568
if (isset($this->labelCache[$key]) && !isset($this->labelCache[$key][$label])) {
@@ -81,7 +84,7 @@ public function removeIssueLabel($issueNumber, string $label, Repository $reposi
8184
}
8285
}
8386

84-
public function addIssueLabels($issueNumber, array $labels, Repository $repository)
87+
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void
8588
{
8689
$key = $this->getCacheKey($issueNumber, $repository);
8790
$labelsToAdd = [];
@@ -121,7 +124,7 @@ public function getComponentLabelsForRepository(Repository $repository): array
121124
{
122125
$key = 'component_labels_'.sha1($repository->getFullName());
123126

124-
return $this->cache->get($key, function (ItemInterface $item) use ($repository) {
127+
return $this->cache->get($key, function (ItemInterface $item) use ($repository): array {
125128
$labels = $this->getAllLabels($repository);
126129
$item->expiresAfter(86400);
127130
$componentLabels = [];
@@ -135,19 +138,22 @@ public function getComponentLabelsForRepository(Repository $repository): array
135138
});
136139
}
137140

141+
/**
142+
* @return array<string, array{name: string, color: string}>
143+
*/
138144
private function getAllLabels(Repository $repository): array
139145
{
140146
$key = 'labels_'.sha1($repository->getFullName());
141147

142-
return $this->cache->get($key, function (ItemInterface $item) use ($repository) {
148+
return $this->cache->get($key, function (ItemInterface $item) use ($repository): array {
143149
$labels = $this->resultPager->fetchAll($this->labelsApi, 'all', [$repository->getVendor(), $repository->getName()]);
144150
$item->expiresAfter(604800);
145151

146152
return $labels;
147153
});
148154
}
149155

150-
private function getCacheKey($issueNumber, Repository $repository)
156+
private function getCacheKey(int $issueNumber, Repository $repository): string
151157
{
152158
return sprintf('%s_%s_%s', $issueNumber, $repository->getVendor(), $repository->getName());
153159
}

src/Api/Label/LabelApi.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
*/
1010
interface LabelApi
1111
{
12-
public function getIssueLabels($issueNumber, Repository $repository): array;
12+
/**
13+
* @return string[]
14+
*/
15+
public function getIssueLabels(int $issueNumber, Repository $repository): array;
1316

14-
public function addIssueLabel($issueNumber, string $label, Repository $repository);
17+
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void;
1518

16-
public function removeIssueLabel($issueNumber, string $label, Repository $repository);
19+
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void;
1720

18-
public function addIssueLabels($issueNumber, array $labels, Repository $repository);
21+
/**
22+
* @param string[] $labels
23+
*/
24+
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void;
1925

2026
/**
2127
* @return string[]

src/Api/Label/NullLabelApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
class NullLabelApi implements LabelApi
1010
{
11-
public function getIssueLabels($issueNumber, Repository $repository): array
11+
public function getIssueLabels(int $issueNumber, Repository $repository): array
1212
{
1313
return [];
1414
}
1515

16-
public function addIssueLabel($issueNumber, string $label, Repository $repository)
16+
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void
1717
{
1818
}
1919

20-
public function removeIssueLabel($issueNumber, string $label, Repository $repository)
20+
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void
2121
{
2222
}
2323

24-
public function addIssueLabels($issueNumber, array $labels, Repository $repository)
24+
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void
2525
{
2626
}
2727

src/Api/Label/StaticLabelApi.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,30 @@
1313
*/
1414
class StaticLabelApi extends NullLabelApi
1515
{
16+
private const array LABELS = [
17+
'Asset', 'AssetMapper', 'BrowserKit', 'Cache', 'Config', 'Console',
18+
'Contracts', 'CssSelector', 'Debug', 'DebugBundle', 'DependencyInjection',
19+
'Doctrine', 'DoctrineBridge', 'DomCrawler', 'Dotenv', 'Emoji',
20+
'Enhancement', 'ErrorHandler', 'EventDispatcher', 'ExpressionLanguage',
21+
'Feature', 'Filesystem', 'Finder', 'Form', 'FrameworkBundle',
22+
'HttpClient', 'HttpFoundation', 'HttpKernel', 'Inflector', 'Intl', 'JsonPath', 'JsonStreamer', 'Ldap',
23+
'Locale', 'Lock', 'Mailer', 'Messenger', 'Mime', 'MonologBridge', 'Notifier', 'ObjectMapper',
24+
'OptionsResolver', 'PasswordHasher', 'PhpUnitBridge', 'Process', 'PropertyAccess',
25+
'PropertyInfo', 'ProxyManagerBridge', 'PsrHttpMessageBridge', 'RemoteEvent', 'Routing',
26+
'Scheduler', 'Security', 'SecurityBundle', 'Serializer', 'Stopwatch', 'String',
27+
'Templating', 'Translation', 'TwigBridge', 'TwigBundle', 'TypeInfo', 'Uid', 'Validator', 'VarDumper',
28+
'VarExporter', 'Webhook', 'WebLink', 'WebProfilerBundle', 'WebServerBundle', 'Workflow',
29+
'Yaml',
30+
];
31+
1632
public function getComponentLabelsForRepository(Repository $repository): array
1733
{
18-
return [
19-
'Asset', 'AssetMapper', 'BrowserKit', 'Cache', 'Config', 'Console',
20-
'Contracts', 'CssSelector', 'Debug', 'DebugBundle', 'DependencyInjection',
21-
'Doctrine', 'DoctrineBridge', 'DomCrawler', 'Dotenv', 'Emoji',
22-
'Enhancement', 'ErrorHandler', 'EventDispatcher', 'ExpressionLanguage',
23-
'Feature', 'Filesystem', 'Finder', 'Form', 'FrameworkBundle',
24-
'HttpClient', 'HttpFoundation', 'HttpKernel', 'Inflector', 'Intl', 'JsonPath', 'JsonStreamer', 'Ldap',
25-
'Locale', 'Lock', 'Mailer', 'Messenger', 'Mime', 'MonologBridge', 'Notifier', 'ObjectMapper',
26-
'OptionsResolver', 'PasswordHasher', 'PhpUnitBridge', 'Process', 'PropertyAccess',
27-
'PropertyInfo', 'ProxyManagerBridge', 'PsrHttpMessageBridge', 'RemoteEvent', 'Routing',
28-
'Scheduler', 'Security', 'SecurityBundle', 'Serializer', 'Stopwatch', 'String',
29-
'Templating', 'Translation', 'TwigBridge', 'TwigBundle', 'TypeInfo', 'Uid', 'Validator', 'VarDumper',
30-
'VarExporter', 'Webhook', 'WebLink', 'WebProfilerBundle', 'WebServerBundle', 'Workflow',
31-
'Yaml',
32-
];
34+
return self::LABELS;
3335
}
3436

3537
public function getAllLabelsForRepository(Repository $repository): array
3638
{
37-
$labels = $this->getComponentLabelsForRepository($repository);
39+
$labels = self::LABELS;
3840
$labels[] = 'BC Break';
3941
$labels[] = 'Bug';
4042
$labels[] = 'Critical';
@@ -47,7 +49,7 @@ public function getAllLabelsForRepository(Repository $repository): array
4749
return $labels;
4850
}
4951

50-
public function getIssueLabels($issueNumber, Repository $repository): array
52+
public function getIssueLabels(int $issueNumber, Repository $repository): array
5153
{
5254
return [];
5355
}

src/Api/Milestone/GithubMilestoneApi.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function __construct(
2222
) {
2323
}
2424

25+
/**
26+
* @return array<array<string, mixed>>
27+
*/
2528
private function getMilestones(Repository $repository): array
2629
{
2730
$key = $this->getCacheKey($repository);

src/Api/PullRequest/GithubPullRequestApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public function __construct(
1717
) {
1818
}
1919

20-
public function show(Repository $repository, $number): array
20+
public function show(Repository $repository, int $number): array
2121
{
2222
return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number);
2323
}
2424

25-
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
25+
public function updateTitle(Repository $repository, int $number, string $title, ?string $body = null): void
2626
{
2727
$params = ['title' => $title];
2828

src/Api/PullRequest/NullPullRequestApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212
class NullPullRequestApi implements PullRequestApi
1313
{
14-
public function show(Repository $repository, $number): array
14+
public function show(Repository $repository, int $number): array
1515
{
1616
return [];
1717
}
1818

19-
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
19+
public function updateTitle(Repository $repository, int $number, string $title, ?string $body = null): void
2020
{
2121
}
2222

src/Api/PullRequest/PullRequestApi.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
*/
1515
interface PullRequestApi
1616
{
17-
public function show(Repository $repository, $number): array;
17+
/**
18+
* @return array<string, mixed>
19+
*/
20+
public function show(Repository $repository, int $number): array;
1821

19-
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void;
22+
public function updateTitle(Repository $repository, int $number, string $title, ?string $body = null): void;
2023

2124
public function getAuthorCount(Repository $repository, string $author): int;
2225
}

0 commit comments

Comments
 (0)