Skip to content

Commit

Permalink
Fix issues detected by PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeliot-Tm committed Dec 11, 2024
1 parent e56c155 commit 54f6427
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
18 changes: 16 additions & 2 deletions scripts/phpstan/baseline.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Github\\\\Api\\\\AbstractApi\\:\\:labels\\(\\)\\.$#"
message: '#^Method Aeliot\\TodoRegistrar\\Console\\Output\:\:openErrorStream\(\) should return resource but returns resource\|false\.$#'
identifier: return.type
count: 2
path: ../../src/Console/Output.php

-
message: '#^Method Aeliot\\TodoRegistrar\\Console\\Output\:\:openOutputStream\(\) should return resource but returns resource\|false\.$#'
identifier: return.type
count: 2
path: ../../src/Console/Output.php

-
message: '#^Call to an undefined method Github\\Api\\AbstractApi\:\:labels\(\)\.$#'
identifier: method.notFound
count: 1
path: ../../src/Service/Registrar/Github/ApiClientFactory.php

-
message: "#^Parameter \\#1 \\$issueAPI of class Aeliot\\\\TodoRegistrar\\\\Service\\\\Registrar\\\\Github\\\\IssueApiClient constructor expects Github\\\\Api\\\\Issue, Github\\\\Api\\\\AbstractApi given\\.$#"
message: '#^Parameter \#1 \$issueAPI of class Aeliot\\TodoRegistrar\\Service\\Registrar\\Github\\IssueApiClient constructor expects Github\\Api\\Issue, Github\\Api\\AbstractApi given\.$#'
identifier: argument.type
count: 1
path: ../../src/Service/Registrar/Github/ApiClientFactory.php
6 changes: 5 additions & 1 deletion src/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ private function createRegistrar(Config $config): RegistrarInterface
}

/**
* @param array<string,mixed> $options
* @param array{
* config: string|null,
* quiet: bool|null,
* verbose: int|string|null
* } $options
*/
private function getConfig(array $options): Config
{
Expand Down
15 changes: 15 additions & 0 deletions src/Console/OptionsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ final class OptionsReader
*/
public function getOptions(): array
{
/**
* @var array{
* config: string|array<string>|null,
* quiet: bool|array<bool>|string|array<string>|null,
* verbose: bool|array<bool>|string|array<string>|int|null
* } $values
*/
$values = [];
/** @var array<string,string> $options */
$options = getopt('c:qv::', ['config:', 'quiet', 'verbose::']);
Expand All @@ -45,6 +52,10 @@ public function getOptions(): array
$values[$long] = $options[$short] ?? $options[$long] ?? $default;
}

if (!(null === $values['config'] || is_string($values['config']))) {
throw new InvalidOptionException('Invalid value for option "config"');
}

if (false === $values['quiet']) {
$values['verbose'] = '-1';
} elseif (null !== $values['quiet']) {
Expand All @@ -59,6 +70,10 @@ public function getOptions(): array
}
}

if (!(null === $values['verbose'] || is_int($values['verbose']) || is_string($values['verbose']))) {
throw new InvalidOptionException('Invalid value for option "config"');
}

return $values;
}
}
5 changes: 3 additions & 2 deletions src/Service/CommentRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ private function registerTodos(array $tokens, Output $output): int
foreach ($tokens as $token) {
$commentParts = $this->commentExtractor->extract($token->text);
foreach ($commentParts->getTodos() as $commentPart) {
if ($commentPart->getTagMetadata()?->getTicketKey()) {
$ticketKey = $commentPart->getTagMetadata()?->getTicketKey();
if ($ticketKey) {
if ($output->isVeryVerbose()) {
$output->writeln("Skip TODO with Key: {$commentPart->getTagMetadata()?->getTicketKey()}");
$output->writeln("Skip TODO with Key: {$ticketKey}");
}
continue;
}
Expand Down

0 comments on commit 54f6427

Please sign in to comment.