Skip to content

chore(phpstan): set level 8, fix issues + bump PHPStan CI version #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
with:
php-version: 8.3
coverage: none
tools: phpstan:1.10, cs2pr
tools: phpstan:2.1, cs2pr

- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 8
reportUnmatchedIgnoredErrors: false
paths:
- src
Expand Down
18 changes: 5 additions & 13 deletions src/Api/Issue/GithubIssueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Api\Issue;

use App\Model\Repository;
use App\Service\TaskHandler\CloseDraftHandler;
use App\Service\TaskHandler\CloseStaleIssuesHandler;
use Github\Api\Issue;
use Github\Api\Issue\Comments;
use Github\Api\Search;
Expand All @@ -21,7 +19,7 @@ public function __construct(
) {
}

public function open(Repository $repository, string $title, string $body, array $labels)
public function open(Repository $repository, string $title, string $body, array $labels): void
{
$params = [
'title' => $title,
Expand All @@ -43,26 +41,20 @@ public function open(Repository $repository, string $title, string $body, array
}
}

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

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

public function show(Repository $repository, $issueNumber): array
public function show(Repository $repository, int $issueNumber): array
{
return $this->issueApi->show($repository->getVendor(), $repository->getName(), $issueNumber);
}

/**
* Close an issue and mark it as "not_planned".
*
* @see CloseDraftHandler
* @see CloseStaleIssuesHandler
*/
public function close(Repository $repository, $issueNumber): void
public function close(Repository $repository, int $issueNumber): void
{
$this->issueApi->update(
$repository->getVendor(),
Expand All @@ -78,7 +70,7 @@ public function close(Repository $repository, $issueNumber): void
/**
* This will comment on both Issues and Pull Requests.
*/
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void
{
$this->issueCommentApi->create(
$repository->getVendor(),
Expand Down
18 changes: 13 additions & 5 deletions src/Api/Issue/IssueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ interface IssueApi
{
/**
* Open new issue or update existing issue.
*
* @param array<string> $labels
*/
public function open(Repository $repository, string $title, string $body, array $labels);
public function open(Repository $repository, string $title, string $body, array $labels): void;

public function show(Repository $repository, $issueNumber): array;
/**
* @return array<string, mixed>
*/
public function show(Repository $repository, int $issueNumber): array;

public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody);
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void;

public function lastCommentWasMadeByBot(Repository $repository, $number): bool;
public function lastCommentWasMadeByBot(Repository $repository, int $number): bool;

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

/**
* Close an issue and mark it as "not_planned".
*/
public function close(Repository $repository, $issueNumber): void;
public function close(Repository $repository, int $issueNumber): void;
}
10 changes: 5 additions & 5 deletions src/Api/Issue/NullIssueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

class NullIssueApi implements IssueApi
{
public function open(Repository $repository, string $title, string $body, array $labels)
public function open(Repository $repository, string $title, string $body, array $labels): void
{
}

public function show(Repository $repository, $issueNumber): array
public function show(Repository $repository, int $issueNumber): array
{
return [];
}

public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
public function commentOnIssue(Repository $repository, int $issueNumber, string $commentBody): void
{
}

public function lastCommentWasMadeByBot(Repository $repository, $number): bool
public function lastCommentWasMadeByBot(Repository $repository, int $number): bool
{
return false;
}
Expand All @@ -29,7 +29,7 @@ public function findStaleIssues(Repository $repository, \DateTimeImmutable $noUp
return [];
}

public function close(Repository $repository, $issueNumber): void
public function close(Repository $repository, int $issueNumber): void
{
}
}
34 changes: 8 additions & 26 deletions src/Api/Label/GithubLabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GithubLabelApi implements LabelApi
/**
* In memory cache for specific issues.
*
* @var array<array-key, array<array-key, bool>>
* @var array<string, array<string, bool>>
*/
private array $labelCache = [];

Expand All @@ -30,7 +30,7 @@ public function __construct(
) {
}

public function getIssueLabels($issueNumber, Repository $repository): array
public function getIssueLabels(int $issueNumber, Repository $repository): array
{
$key = $this->getCacheKey($issueNumber, $repository);
if (!isset($this->labelCache[$key])) {
Expand All @@ -54,12 +54,12 @@ public function getIssueLabels($issueNumber, Repository $repository): array
return $labels;
}

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

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

public function addIssueLabels($issueNumber, array $labels, Repository $repository)
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void
{
$key = $this->getCacheKey($issueNumber, $repository);
$labelsToAdd = [];
Expand Down Expand Up @@ -115,39 +115,21 @@ public function getAllLabelsForRepository(Repository $repository): array
}

/**
* @return string[]
* @return array<array{name: string, color: string}>
*/
public function getComponentLabelsForRepository(Repository $repository): array
{
$key = 'component_labels_'.sha1($repository->getFullName());

return $this->cache->get($key, function (ItemInterface $item) use ($repository) {
$labels = $this->getAllLabels($repository);
$item->expiresAfter(86400);
$componentLabels = [];
foreach ($labels as $label) {
if ('dddddd' === strtolower($label['color'])) {
$componentLabels[] = $label['name'];
}
}

return $componentLabels;
});
}

private function getAllLabels(Repository $repository): array
{
$key = 'labels_'.sha1($repository->getFullName());

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

return $labels;
});
}

private function getCacheKey($issueNumber, Repository $repository)
private function getCacheKey(int $issueNumber, Repository $repository): string
{
return sprintf('%s_%s_%s', $issueNumber, $repository->getVendor(), $repository->getName());
}
Expand Down
17 changes: 9 additions & 8 deletions src/Api/Label/LabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
*/
interface LabelApi
{
public function getIssueLabels($issueNumber, Repository $repository): array;

public function addIssueLabel($issueNumber, string $label, Repository $repository);
/**
* @return string[]
*/
public function getIssueLabels(int $issueNumber, Repository $repository): array;

public function removeIssueLabel($issueNumber, string $label, Repository $repository);
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void;

public function addIssueLabels($issueNumber, array $labels, Repository $repository);
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void;

/**
* @return string[]
* @param string[] $labels
*/
public function getAllLabelsForRepository(Repository $repository): array;
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void;

/**
* @return string[]
*/
public function getComponentLabelsForRepository(Repository $repository): array;
public function getAllLabelsForRepository(Repository $repository): array;
}
13 changes: 4 additions & 9 deletions src/Api/Label/NullLabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,25 @@

class NullLabelApi implements LabelApi
{
public function getIssueLabels($issueNumber, Repository $repository): array
public function getIssueLabels(int $issueNumber, Repository $repository): array
{
return [];
}

public function addIssueLabel($issueNumber, string $label, Repository $repository)
public function addIssueLabel(int $issueNumber, string $label, Repository $repository): void
{
}

public function removeIssueLabel($issueNumber, string $label, Repository $repository)
public function removeIssueLabel(int $issueNumber, string $label, Repository $repository): void
{
}

public function addIssueLabels($issueNumber, array $labels, Repository $repository)
public function addIssueLabels(int $issueNumber, array $labels, Repository $repository): void
{
}

public function getAllLabelsForRepository(Repository $repository): array
{
return [];
}

public function getComponentLabelsForRepository(Repository $repository): array
{
return [];
}
}
37 changes: 17 additions & 20 deletions src/Api/Label/StaticLabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,25 @@
*/
class StaticLabelApi extends NullLabelApi
{
public function getComponentLabelsForRepository(Repository $repository): array
{
return [
'Asset', 'AssetMapper', 'BrowserKit', 'Cache', 'Config', 'Console',
'Contracts', 'CssSelector', 'Debug', 'DebugBundle', 'DependencyInjection',
'Doctrine', 'DoctrineBridge', 'DomCrawler', 'Dotenv', 'Emoji',
'Enhancement', 'ErrorHandler', 'EventDispatcher', 'ExpressionLanguage',
'Feature', 'Filesystem', 'Finder', 'Form', 'FrameworkBundle',
'HttpClient', 'HttpFoundation', 'HttpKernel', 'Inflector', 'Intl', 'JsonPath', 'JsonStreamer', 'Ldap',
'Locale', 'Lock', 'Mailer', 'Messenger', 'Mime', 'MonologBridge', 'Notifier', 'ObjectMapper',
'OptionsResolver', 'PasswordHasher', 'PhpUnitBridge', 'Process', 'PropertyAccess',
'PropertyInfo', 'ProxyManagerBridge', 'PsrHttpMessageBridge', 'RemoteEvent', 'Routing',
'Scheduler', 'Security', 'SecurityBundle', 'Serializer', 'Stopwatch', 'String',
'Templating', 'Translation', 'TwigBridge', 'TwigBundle', 'TypeInfo', 'Uid', 'Validator', 'VarDumper',
'VarExporter', 'Webhook', 'WebLink', 'WebProfilerBundle', 'WebServerBundle', 'Workflow',
'Yaml',
];
}
private const array LABELS = [
'Asset', 'AssetMapper', 'BrowserKit', 'Cache', 'Config', 'Console',
'Contracts', 'CssSelector', 'Debug', 'DebugBundle', 'DependencyInjection',
'Doctrine', 'DoctrineBridge', 'DomCrawler', 'Dotenv', 'Emoji',
'Enhancement', 'ErrorHandler', 'EventDispatcher', 'ExpressionLanguage',
'Feature', 'Filesystem', 'Finder', 'Form', 'FrameworkBundle',
'HttpClient', 'HttpFoundation', 'HttpKernel', 'Inflector', 'Intl', 'JsonPath', 'JsonStreamer', 'Ldap',
'Locale', 'Lock', 'Mailer', 'Messenger', 'Mime', 'MonologBridge', 'Notifier', 'ObjectMapper',
'OptionsResolver', 'PasswordHasher', 'PhpUnitBridge', 'Process', 'PropertyAccess',
'PropertyInfo', 'ProxyManagerBridge', 'PsrHttpMessageBridge', 'RemoteEvent', 'Routing',
'Scheduler', 'Security', 'SecurityBundle', 'Serializer', 'Stopwatch', 'String',
'Templating', 'Translation', 'TwigBridge', 'TwigBundle', 'TypeInfo', 'Uid', 'Validator', 'VarDumper',
'VarExporter', 'Webhook', 'WebLink', 'WebProfilerBundle', 'WebServerBundle', 'Workflow',
'Yaml',
];

public function getAllLabelsForRepository(Repository $repository): array
{
$labels = $this->getComponentLabelsForRepository($repository);
$labels = self::LABELS;
$labels[] = 'BC Break';
$labels[] = 'Bug';
$labels[] = 'Critical';
Expand All @@ -47,7 +44,7 @@ public function getAllLabelsForRepository(Repository $repository): array
return $labels;
}

public function getIssueLabels($issueNumber, Repository $repository): array
public function getIssueLabels(int $issueNumber, Repository $repository): array
{
return [];
}
Expand Down
5 changes: 4 additions & 1 deletion src/Api/Milestone/GithubMilestoneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class GithubMilestoneApi implements MilestoneApi
{
/**
* @var string[][]
* @var array<string, array<int, array{title: string, number: int}>>
*/
private array $cache = [];

Expand All @@ -22,6 +22,9 @@ public function __construct(
) {
}

/**
* @return array<int, array{title: string, number: int}>
*/
private function getMilestones(Repository $repository): array
{
$key = $this->getCacheKey($repository);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/PullRequest/GithubPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public function __construct(
) {
}

public function show(Repository $repository, $number): array
public function show(Repository $repository, int $number): array
{
return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number);
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/Api/PullRequest/NullPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/
class NullPullRequestApi implements PullRequestApi
{
public function show(Repository $repository, $number): array
public function show(Repository $repository, int $number): array
{
return [];
}

public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
public function updateTitle(Repository $repository, int $number, string $title, ?string $body = null): void
{
}

Expand Down
Loading