Skip to content

Commit

Permalink
Bump PHPStan to ^2 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake authored Dec 16, 2024
1 parent 609125d commit f37ea54
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
continue-on-error: true
run: |
composer config --no-plugins allow-plugins.phpstan/extension-installer true
composer require --ansi --dev "vimeo/psalm:^5.15" "phpstan/phpstan:>=1.10" "phpstan/extension-installer:>=1.4" "phpstan/phpstan-phpunit:>=1.4" "squizlabs/php_codesniffer:>=3.7" "phpunit/phpunit:>=10"
composer require --ansi --dev "vimeo/psalm:^5.15" "phpstan/phpstan:>=2" "phpstan/extension-installer:>=1.4" "phpstan/phpstan-phpunit:>=1.4" "squizlabs/php_codesniffer:>=3.7" "phpunit/phpunit:>=10"
- name: "Run static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan"
Expand Down
79 changes: 79 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
parameters:
ignoreErrors:
-
message: '#^Call to function is_string\(\) with class\-string\<FileEye\\MimeMap\\Map\\MimeMapInterface\> will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Cannot access offset 0 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Cannot access offset 1 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Cannot access offset 2 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Parameter \#2 \$args of function call_user_func_array expects array\<int\|string, mixed\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Part \$command\[0\] \(mixed\) of encapsed string cannot be cast to string\.$#'
identifier: encapsedStringPart.nonString
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Part \$error \(mixed\) of encapsed string cannot be cast to string\.$#'
identifier: encapsedStringPart.nonString
count: 1
path: src/Command/UpdateCommand.php

-
message: '#^Method FileEye\\MimeMap\\Map\\BaseMap\:\:getMapSubEntry\(\) should return list\<string\> but returns array\<int, string\>\.$#'
identifier: return.type
count: 1
path: src/Map/BaseMap.php

-
message: '#^Method FileEye\\MimeMap\\Map\\BaseMap\:\:listEntries\(\) should return list\<int\|string\> but returns array\<int\<0, max\>, int\|string\>\.$#'
identifier: return.type
count: 1
path: src/Map/BaseMap.php

-
message: '#^Binary operation "\." between ''\: '' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/MapUpdater.php

-
message: '#^Parameter \#1 \$format of method FileEye\\MimeMap\\Type\:\:toString\(\) expects int, mixed given\.$#'
identifier: argument.type
count: 7
path: src/Type.php

-
message: '#^Parameter \#1 \$format of method FileEye\\MimeMap\\TypeInterface\:\:toString\(\) expects int, mixed given\.$#'
identifier: argument.type
count: 3
path: src/Type.php

-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''FileEye\\\\MimeMap\\\\TypeParameter'' and FileEye\\MimeMap\\TypeParameter will always evaluate to true\.$#'
identifier: method.alreadyNarrowedType
count: 1
path: tests/src/TypeTest.php
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
includes:
- phpstan-baseline.neon

parameters:
level: max

paths:
- src
- tests
Expand Down
8 changes: 4 additions & 4 deletions src/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ protected function configure(): void
null,
InputOption::VALUE_REQUIRED,
'File name of the script containing the sequence of commands to execute to build the default map.',
MapUpdater::getDefaultMapBuildFile()
MapUpdater::getDefaultMapBuildFile(),
)
->addOption(
'class',
null,
InputOption::VALUE_REQUIRED,
'The fully qualified class name of the PHP class storing the map.',
MapHandler::DEFAULT_MAP_CLASS
MapHandler::DEFAULT_MAP_CLASS,
)
->addOption(
'diff',
null,
InputOption::VALUE_NONE,
'Report updates.'
'Report updates.',
)
->addOption(
'fail-on-diff',
null,
InputOption::VALUE_NONE,
'Exit with an error when a difference is found. Map will not be updated.'
'Exit with an error when a difference is found. Map will not be updated.',
)
;
}
Expand Down
5 changes: 3 additions & 2 deletions src/MapUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ public function loadMapFromFreedesktopFile(string $source_file): array
}
if (isset($node->acronym)) {
$acronym = (string) $node->acronym;
if (isset($node->{'expanded-acronym'})) {
$acronym .= ': ' . (string) $node->{'expanded-acronym'};
$expandedAcronym = $node->{'expanded-acronym'} ?? null;
if (isset($expandedAcronym)) {
$acronym .= ': ' . $expandedAcronym;
}
$this->map->addTypeDescription($type, $acronym);
}
Expand Down

0 comments on commit f37ea54

Please sign in to comment.