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 Jul 31, 2024
1 parent b86ee15 commit 0f6c2a6
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 68 deletions.
64 changes: 0 additions & 64 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,66 +1,2 @@
parameters:
ignoreErrors:
-
message: "#^Property Aeliot\\\\TodoRegistrar\\\\Dto\\\\InlineConfig\\\\IndexedCollection\\:\\:\\$data type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Dto/InlineConfig/IndexedCollection.php

-
message: "#^Property Aeliot\\\\TodoRegistrar\\\\Dto\\\\InlineConfig\\\\NamedCollection\\:\\:\\$data type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Dto/InlineConfig/NamedCollection.php

-
message: "#^Interface Aeliot\\\\TodoRegistrar\\\\InlineConfigInterface extends generic interface ArrayAccess but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/InlineConfigInterface.php

-
message: "#^Cannot access offset int\\<0, max\\> on array\\<int, string\\>\\|false\\.$#"
count: 1
path: src/Service/Comment/Extractor.php

-
message: "#^Cannot assign offset int\\<0, max\\> to array\\<int, string\\>\\|false\\.$#"
count: 1
path: src/Service/Comment/Extractor.php

-
message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: src/Service/Comment/Extractor.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: src/Service/Comment/Extractor.php

-
message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: src/Service/Comment/Extractor.php

-
message: "#^Parameter \\#1 \\$code of static method Symfony\\\\Polyfill\\\\Php80\\\\PhpToken\\:\\:tokenize\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/Service/File/Tokenizer.php

-
message: "#^Instanceof between array\\<int, JiraRestApi\\\\IssueLink\\\\IssueLinkType\\> and IteratorAggregate will always evaluate to false\\.$#"
count: 1
path: src/Service/Registrar/JIRA/IssueLinkTypeProvider.php

-
message: "#^Instanceof between array\\<int, JiraRestApi\\\\IssueLink\\\\IssueLinkType\\> and Traversable will always evaluate to false\\.$#"
count: 1
path: src/Service/Registrar/JIRA/IssueLinkTypeProvider.php

-
message: "#^Method Aeliot\\\\TodoRegistrar\\\\Service\\\\Registrar\\\\JIRA\\\\LinkedIssueNormalizer\\:\\:normalizeLinkedIssues\\(\\) should return array\\<string, array\\<string\\>\\> but returns array\\<string, array\\<int, array\\<string\\>\\|string\\>\\>\\.$#"
count: 1
path: src/Service/Registrar/JIRA/LinkedIssueNormalizer.php

-
message: "#^Parameter \\#1 \\$array of function array_is_list expects array, array\\<array\\<string\\>\\|string\\>\\|string given\\.$#"
count: 1
path: src/Service/Registrar/JIRA/LinkedIssueNormalizer.php
2 changes: 1 addition & 1 deletion src/Dto/InlineConfig/IndexedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class IndexedCollection implements CollectionInterface
{
/**
* @return array<array-key,mixed>
* @var array<int,mixed>
*/
private array $data = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Dto/InlineConfig/NamedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
final class NamedCollection implements CollectionInterface
{
/**
* @return array<array-key,mixed>
* @var array<string,mixed>
*/
private array $data = [];

Expand Down
3 changes: 3 additions & 0 deletions src/InlineConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Aeliot\TodoRegistrar;

/**
* @template-extends \ArrayAccess<string,mixed>
*/
interface InlineConfigInterface extends \ArrayAccess
{
}
1 change: 1 addition & 0 deletions src/Service/Comment/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private function registerPart(string $line, CommentParts $parts): CommentPart
*/
private function splitLines(string $comment): array
{
/** @var string[] $lines */
$lines = preg_split("/([\r\n]+)/", $comment, -1, \PREG_SPLIT_DELIM_CAPTURE);
$count = \count($lines);
$currentLineIndex = 0;
Expand Down
8 changes: 7 additions & 1 deletion src/Service/File/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Tokenizer
*/
public function tokenize(\SplFileInfo $file): array
{
return \PhpToken::tokenize(file_get_contents($file->getPathname()));
$pathname = $file->getPathname();
$contents = file_get_contents($pathname);
if (false === $contents) {
throw new \RuntimeException(\sprintf('Cannot read file %s', $pathname));
}

return \PhpToken::tokenize($contents);
}
}
2 changes: 1 addition & 1 deletion src/Service/Registrar/JIRA/IssueLinkTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getLinkType(string $alias): IssueLinkType
private function getSupportedLinkTypes(): array
{
if (null === $this->supportedLinkTypes) {
/** @var \ArrayObject<int,IssueLinkType>|IssueLinkType[] $issueLinkTypes */
/** @var \ArrayObject<int,IssueLinkType>|iterable<IssueLinkType>|IssueLinkType[] $issueLinkTypes */
$issueLinkTypes = $this->serviceFactory->createIssueLinkService()->getIssueLinkTypes();
if ($issueLinkTypes instanceof \ArrayObject) {
$issueLinkTypes = $issueLinkTypes->getArrayCopy();
Expand Down
1 change: 1 addition & 0 deletions src/Service/Registrar/JIRA/LinkedIssueNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function normalizeLinkedIssues(array $linkedIssues): array

$result = [];

/** @var array<string,array<string>> $linkedIssues */
foreach ($linkedIssues as $issueLinkTypeAlias => $issueKeys) {
if (!array_is_list($issueKeys)) {
throw new InvalidInlineConfigFormatException('List of liked issues must be indexed array of strings');
Expand Down

0 comments on commit 0f6c2a6

Please sign in to comment.