Skip to content

Commit 2206603

Browse files
smnandrefabpot
authored andcommitted
chore(phpstan): set level 8, fix issues + bump PHPStan CI version
1 parent fbfa656 commit 2206603

34 files changed

+217
-210
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
php-version: 8.3
5656
coverage: none
57-
tools: phpstan:1.10, cs2pr
57+
tools: phpstan:2.1, cs2pr
5858

5959
- name: Checkout code
6060
uses: actions/checkout@v4

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: 8
33
reportUnmatchedIgnoredErrors: false
44
paths:
55
- src

src/Api/Issue/GithubIssueApi.php

Lines changed: 5 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,20 @@ 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+
public function show(Repository $repository, int $issueNumber): array
5553
{
5654
return $this->issueApi->show($repository->getVendor(), $repository->getName(), $issueNumber);
5755
}
5856

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
57+
public function close(Repository $repository, int $issueNumber): void
6658
{
6759
$this->issueApi->update(
6860
$repository->getVendor(),
@@ -78,7 +70,7 @@ public function close(Repository $repository, $issueNumber): void
7870
/**
7971
* This will comment on both Issues and Pull Requests.
8072
*/
81-
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
73+
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void
8274
{
8375
$this->issueCommentApi->create(
8476
$repository->getVendor(),

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: 8 additions & 26 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,7 @@ public function __construct(
3030
) {
3131
}
3232

33-
public function getIssueLabels($issueNumber, Repository $repository): array
33+
public function getIssueLabels(int $issueNumber, Repository $repository): array
3434
{
3535
$key = $this->getCacheKey($issueNumber, $repository);
3636
if (!isset($this->labelCache[$key])) {
@@ -54,12 +54,12 @@ public function getIssueLabels($issueNumber, Repository $repository): array
5454
return $labels;
5555
}
5656

57-
public function addIssueLabel($issueNumber, string $label, Repository $repository)
57+
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void
5858
{
5959
$this->addIssueLabels($issueNumber, [$label], $repository);
6060
}
6161

62-
public function removeIssueLabel($issueNumber, string $label, Repository $repository)
62+
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void
6363
{
6464
$key = $this->getCacheKey($issueNumber, $repository);
6565
if (isset($this->labelCache[$key]) && !isset($this->labelCache[$key][$label])) {
@@ -81,7 +81,7 @@ public function removeIssueLabel($issueNumber, string $label, Repository $reposi
8181
}
8282
}
8383

84-
public function addIssueLabels($issueNumber, array $labels, Repository $repository)
84+
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void
8585
{
8686
$key = $this->getCacheKey($issueNumber, $repository);
8787
$labelsToAdd = [];
@@ -115,39 +115,21 @@ public function getAllLabelsForRepository(Repository $repository): array
115115
}
116116

117117
/**
118-
* @return string[]
118+
* @return array<array{name: string, color: string}>
119119
*/
120-
public function getComponentLabelsForRepository(Repository $repository): array
121-
{
122-
$key = 'component_labels_'.sha1($repository->getFullName());
123-
124-
return $this->cache->get($key, function (ItemInterface $item) use ($repository) {
125-
$labels = $this->getAllLabels($repository);
126-
$item->expiresAfter(86400);
127-
$componentLabels = [];
128-
foreach ($labels as $label) {
129-
if ('dddddd' === strtolower($label['color'])) {
130-
$componentLabels[] = $label['name'];
131-
}
132-
}
133-
134-
return $componentLabels;
135-
});
136-
}
137-
138120
private function getAllLabels(Repository $repository): array
139121
{
140122
$key = 'labels_'.sha1($repository->getFullName());
141123

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

146128
return $labels;
147129
});
148130
}
149131

150-
private function getCacheKey($issueNumber, Repository $repository)
132+
private function getCacheKey(int $issueNumber, Repository $repository): string
151133
{
152134
return sprintf('%s_%s_%s', $issueNumber, $repository->getVendor(), $repository->getName());
153135
}

src/Api/Label/LabelApi.php

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

16-
public function removeIssueLabel($issueNumber, string $label, Repository $repository);
17+
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void;
1718

18-
public function addIssueLabels($issueNumber, array $labels, Repository $repository);
19+
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void;
1920

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

2526
/**
2627
* @return string[]
2728
*/
28-
public function getComponentLabelsForRepository(Repository $repository): array;
29+
public function getAllLabelsForRepository(Repository $repository): array;
2930
}

src/Api/Label/NullLabelApi.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,25 @@
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

2828
public function getAllLabelsForRepository(Repository $repository): array
2929
{
3030
return [];
3131
}
32-
33-
public function getComponentLabelsForRepository(Repository $repository): array
34-
{
35-
return [];
36-
}
3732
}

src/Api/Label/StaticLabelApi.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,25 @@
1313
*/
1414
class StaticLabelApi extends NullLabelApi
1515
{
16-
public function getComponentLabelsForRepository(Repository $repository): array
17-
{
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-
];
33-
}
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+
];
3431

3532
public function getAllLabelsForRepository(Repository $repository): array
3633
{
37-
$labels = $this->getComponentLabelsForRepository($repository);
34+
$labels = self::LABELS;
3835
$labels[] = 'BC Break';
3936
$labels[] = 'Bug';
4037
$labels[] = 'Critical';
@@ -47,7 +44,7 @@ public function getAllLabelsForRepository(Repository $repository): array
4744
return $labels;
4845
}
4946

50-
public function getIssueLabels($issueNumber, Repository $repository): array
47+
public function getIssueLabels(int $issueNumber, Repository $repository): array
5148
{
5249
return [];
5350
}

src/Api/Milestone/GithubMilestoneApi.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class GithubMilestoneApi implements MilestoneApi
1313
{
1414
/**
15-
* @var string[][]
15+
* @var array<string, array<int, array{title: string, number: int}>>
1616
*/
1717
private array $cache = [];
1818

@@ -22,6 +22,9 @@ public function __construct(
2222
) {
2323
}
2424

25+
/**
26+
* @return array<int, array{title: string, number: int}>
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

0 commit comments

Comments
 (0)