Skip to content

Commit

Permalink
Fix phpstan issues, update baseline and pin PHPStan version in 2.2 br…
Browse files Browse the repository at this point in the history
…anch (#10474)
  • Loading branch information
Seldaek committed Jan 21, 2022
1 parent e103ee0 commit e3d99ca
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- name: "Install PHPStan"
# Locked to phpunit 7.5 here as newer ones have void return types which break inheritance
run: "bin/composer require --dev phpstan/phpstan:^1.0 phpstan/phpstan-phpunit:^1.0 phpstan/phpstan-deprecation-rules:^1 phpstan/phpstan-strict-rules:^1 phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}"
run: "bin/composer require --dev phpstan/phpstan:1.4.* phpstan/phpstan-phpunit:1.0.* phpstan/phpstan-deprecation-rules:1.0.* phpstan/phpstan-strict-rules:1.1.* phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}"

- name: "Run PHPStan"
run: "vendor/bin/phpstan analyse --configuration=phpstan/config.neon"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"phpstan-setup": [
"@composer config platform --unset",
"@composer update",
"@composer require --dev phpstan/phpstan:^1.0 phpstan/phpstan-phpunit:^1.0 phpstan/phpstan-deprecation-rules:^1 phpstan/phpstan-strict-rules:^1 phpunit/phpunit:^7.5.20 --with-all-dependencies",
"@composer require --dev phpstan/phpstan:1.4.* phpstan/phpstan-phpunit:1.0.* phpstan/phpstan-deprecation-rules:1.0.* phpstan/phpstan-strict-rules:1.1.* phpunit/phpunit:^7.5.20 --with-all-dependencies",
"git checkout composer.json composer.lock"
],
"phpstan": "@php vendor/bin/phpstan analyse --configuration=phpstan/config.neon"
Expand Down
163 changes: 31 additions & 132 deletions phpstan/baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Argument of an invalid type array\\<string\\>\\|string supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../src/Composer/Autoload/AutoloadGenerator.php

-
message: "#^Binary operation \"\\.\" between non\\-empty\\-string and array\\|string\\|null results in an error\\.$#"
count: 1
Expand Down Expand Up @@ -110,11 +105,6 @@ parameters:
count: 3
path: ../src/Composer/Autoload/AutoloadGenerator.php

-
message: "#^Parameter \\#1 \\$files of method Composer\\\\Autoload\\\\AutoloadGenerator\\:\\:getIncludeFilesFile\\(\\) expects array\\<string, string\\>, array\\<int\\|string, array\\<string\\>\\|string\\> given\\.$#"
count: 1
path: ../src/Composer/Autoload/AutoloadGenerator.php

-
message: "#^Parameter \\#1 \\$from of method Composer\\\\Util\\\\Filesystem\\:\\:findShortestPathCode\\(\\) expects string, string\\|false given\\.$#"
count: 5
Expand Down Expand Up @@ -165,11 +155,6 @@ parameters:
count: 1
path: ../src/Composer/Autoload/AutoloadGenerator.php

-
message: "#^Parameter \\#6 \\$namespaceFilter of method Composer\\\\Autoload\\\\AutoloadGenerator\\:\\:addClassMapCode\\(\\) expects string\\|null, int\\|string given\\.$#"
count: 1
path: ../src/Composer/Autoload/AutoloadGenerator.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 2
Expand Down Expand Up @@ -1175,6 +1160,11 @@ parameters:
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Property Composer\\\\Command\\\\InitCommand\\:\\:\\$gitConfig \\(array\\<string, string\\>\\) does not accept array\\<int\\|string, mixed\\>\\.$#"
count: 1
path: ../src/Composer/Command/InitCommand.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 15
Expand Down Expand Up @@ -2485,11 +2475,6 @@ parameters:
count: 1
path: ../src/Composer/Config.php

-
message: "#^Array \\(array\\<string, true\\>\\) does not accept key 0\\|string\\.$#"
count: 1
path: ../src/Composer/Config.php

-
message: "#^Call to function array_search\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
Expand Down Expand Up @@ -3005,11 +2990,6 @@ parameters:
count: 2
path: ../src/Composer/DependencyResolver/Rule.php

-
message: "#^Array \\(array\\<string, array\\<Composer\\\\DependencyResolver\\\\Rule\\>\\|Composer\\\\DependencyResolver\\\\Rule\\>\\) does not accept key int\\|string\\.$#"
count: 2
path: ../src/Composer/DependencyResolver/RuleSet.php

-
message: "#^Method Composer\\\\DependencyResolver\\\\RuleSet\\:\\:getTypes\\(\\) should return array\\{0, 1, 4\\} but returns array\\<int, 0\\|1\\|4\\>\\.$#"
count: 1
Expand Down Expand Up @@ -3080,11 +3060,6 @@ parameters:
count: 1
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Casting to int something that's already int\\.$#"
count: 2
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
Expand All @@ -3100,11 +3075,6 @@ parameters:
count: 1
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Only booleans are allowed in &&, int given on the left side\\.$#"
count: 1
path: ../src/Composer/DependencyResolver/Solver.php

-
message: "#^Only booleans are allowed in &&, int\\<0, max\\> given on the right side\\.$#"
count: 2
Expand All @@ -3127,7 +3097,7 @@ parameters:

-
message: "#^Only booleans are allowed in a negated boolean, int given\\.$#"
count: 3
count: 1
path: ../src/Composer/DependencyResolver/Solver.php

-
Expand Down Expand Up @@ -3980,11 +3950,6 @@ parameters:
count: 5
path: ../src/Composer/Factory.php

-
message: "#^Array \\(array\\<string, array\\{username\\: string, password\\: string\\}\\>\\) does not accept array\\{username\\: string, password\\: string\\|null\\}\\.$#"
count: 1
path: ../src/Composer/IO/BaseIO.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
Expand Down Expand Up @@ -4050,11 +4015,6 @@ parameters:
count: 1
path: ../src/Composer/IO/ConsoleIO.php

-
message: "#^Array \\(array\\<string, array\\<string, array\\<string, array\\<array\\<string\\>\\|bool\\|string\\>\\|bool\\|string\\>\\>\\>\\) does not accept key \\(int\\|string\\)\\.$#"
count: 1
path: ../src/Composer/InstalledVersions.php

-
message: "#^Call to function method_exists\\(\\) with 'Composer\\\\\\\\Autoload…' and 'getRegisteredLoaders' will always evaluate to true\\.$#"
count: 1
Expand Down Expand Up @@ -4085,11 +4045,6 @@ parameters:
count: 15
path: ../src/Composer/Installer.php

-
message: "#^Method Composer\\\\Installer\\:\\:run\\(\\) should return 0\\|1\\|2\\|3\\|4 but returns int\\<min, \\-1\\>\\|int\\<1, max\\>\\.$#"
count: 1
path: ../src/Composer/Installer.php

-
message: "#^Only booleans are allowed in &&, array\\<array\\<string, string\\>\\> given on the right side\\.$#"
count: 1
Expand Down Expand Up @@ -4150,11 +4105,6 @@ parameters:
count: 1
path: ../src/Composer/Installer.php

-
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
count: 1
path: ../src/Composer/Installer.php

-
message: "#^Only booleans are allowed in \\|\\|, array\\<string\\>\\|null given on the left side\\.$#"
count: 2
Expand Down Expand Up @@ -4235,6 +4185,11 @@ parameters:
count: 2
path: ../src/Composer/Installer/InstallationManager.php

-
message: "#^Constant PHP_WINDOWS_EVENT_CTRL_C not found\\.$#"
count: 1
path: ../src/Composer/Installer/InstallationManager.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
Expand All @@ -4245,6 +4200,11 @@ parameters:
count: 2
path: ../src/Composer/Installer/InstallationManager.php

-
message: "#^Function sapi_windows_set_ctrl_handler not found\\.$#"
count: 3
path: ../src/Composer/Installer/InstallationManager.php

-
message: "#^Only booleans are allowed in &&, Composer\\\\EventDispatcher\\\\EventDispatcher\\|null given on the right side\\.$#"
count: 2
Expand Down Expand Up @@ -4450,11 +4410,6 @@ parameters:
count: 1
path: ../src/Composer/Json/JsonFile.php

-
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
count: 1
path: ../src/Composer/Json/JsonFile.php

-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -4625,11 +4580,6 @@ parameters:
count: 1
path: ../src/Composer/Package/BasePackage.php

-
message: "#^Method Composer\\\\Package\\\\Comparer\\\\Comparer\\:\\:getChanged\\(\\) should return array\\{changed\\?\\: array\\<string\\>, removed\\?\\: array\\<string\\>, added\\?\\: array\\<string\\>\\}\\|string\\|false but returns \\(non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, array\\<string\\>\\>\\)\\|string\\.$#"
count: 1
path: ../src/Composer/Package/Comparer/Comparer.php

-
message: "#^Only booleans are allowed in &&, int\\<0, max\\>\\|false given on the right side\\.$#"
count: 1
Expand Down Expand Up @@ -5115,11 +5065,6 @@ parameters:
count: 1
path: ../src/Composer/Platform/Runtime.php

-
message: "#^Array \\(array\\<string, Composer\\\\Plugin\\\\PluginInterface\\>\\) does not accept object\\.$#"
count: 2
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Cannot call method getInstallationManager\\(\\) on Composer\\\\Composer\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -5195,21 +5140,11 @@ parameters:
count: 1
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Parameter \\#1 \\$installer of method Composer\\\\Installer\\\\InstallationManager\\:\\:addInstaller\\(\\) expects Composer\\\\Installer\\\\InstallerInterface, object given\\.$#"
count: 1
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
count: 1
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Parameter \\#1 \\$plugin of method Composer\\\\Plugin\\\\PluginManager\\:\\:addPlugin\\(\\) expects Composer\\\\Plugin\\\\PluginInterface, object given\\.$#"
count: 1
path: ../src/Composer/Plugin/PluginManager.php

-
message: "#^Parameter \\#3 \\$subject of static method Composer\\\\Pcre\\\\Preg\\:\\:replace\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -5275,11 +5210,6 @@ parameters:
count: 3
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Argument of an invalid type array\\<string, Composer\\\\Package\\\\PackageInterface\\>\\|null supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Cannot access offset 'path' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\|false\\.$#"
count: 1
Expand Down Expand Up @@ -5420,11 +5350,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 3
Expand All @@ -5445,11 +5370,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\<string, Composer\\\\Package\\\\PackageInterface\\>\\|null given\\.$#"
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
count: 3
Expand Down Expand Up @@ -5920,11 +5840,6 @@ parameters:
count: 1
path: ../src/Composer/Repository/Vcs/GitDriver.php

-
message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitDriver\\:\\:\\$branches \\(array\\<string, string\\>\\) does not accept array\\<int\\|string, mixed\\>\\.$#"
count: 1
path: ../src/Composer/Repository/Vcs/GitDriver.php

-
message: "#^Call to function array_search\\(\\) requires parameter \\#3 to be set\\.$#"
count: 2
Expand Down Expand Up @@ -6725,11 +6640,6 @@ parameters:
count: 2
path: ../src/Composer/Util/Hg.php

-
message: "#^Array \\(array\\<array\\{url\\: string, origin\\: string, attributes\\: array\\{retryAuthFailure\\: bool, redirects\\: int, retries\\: int, storeAuth\\: bool\\}, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|false, headerHandle\\: resource, \\.\\.\\.\\}\\>\\) does not accept array\\{url\\: string, origin\\: string, attributes\\: non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, bool\\|int\\>, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|null, headerHandle\\: resource\\|false, \\.\\.\\.\\}\\.$#"
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
Expand Down Expand Up @@ -6920,6 +6830,11 @@ parameters:
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php

-
message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$jobs \\(array\\<array\\{url\\: string, origin\\: string, attributes\\: array\\{retryAuthFailure\\: bool, redirects\\: int, retries\\: int, storeAuth\\: bool\\}, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|false, headerHandle\\: resource, \\.\\.\\.\\}\\>\\) does not accept non\\-empty\\-array\\<array\\{url\\: string, origin\\: string, attributes\\: array\\<literal\\-string&non\\-empty\\-string, bool\\|int\\>, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|false\\|null, headerHandle\\: resource, \\.\\.\\.\\}\\>\\.$#"
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php

-
message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$multiHandle \\(resource\\|null\\) does not accept resource\\|false\\.$#"
count: 1
Expand Down Expand Up @@ -7155,11 +7070,6 @@ parameters:
count: 2
path: ../src/Composer/Util/Loop.php

-
message: "#^Cannot access offset int\\<min, 16\\> on array\\|false\\.$#"
count: 6
path: ../src/Composer/Util/NoProxyPattern.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
Expand Down Expand Up @@ -7345,11 +7255,6 @@ parameters:
count: 1
path: ../src/Composer/Util/ProcessExecutor.php

-
message: "#^Only booleans are allowed in &&, Composer\\\\IO\\\\IOInterface\\|null given on the left side\\.$#"
count: 2
path: ../src/Composer/Util/ProcessExecutor.php

-
message: "#^Only booleans are allowed in &&, string\\|false given on the right side\\.$#"
count: 2
Expand All @@ -7370,9 +7275,14 @@ parameters:
count: 1
path: ../src/Composer/Util/ProcessExecutor.php

-
message: "#^Property Composer\\\\Util\\\\ProcessExecutor\\:\\:\\$jobs \\(array\\<int, array\\<string, mixed\\>\\>\\) does not accept array\\<int\\|string, array\\<string, mixed\\>\\>\\.$#"
count: 1
path: ../src/Composer/Util/ProcessExecutor.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 2
count: 1
path: ../src/Composer/Util/ProcessExecutor.php

-
Expand Down Expand Up @@ -8226,16 +8136,10 @@ parameters:
path: ../tests/Composer/Test/EventDispatcher/EventDispatcherTest.php

-
message: "#^Call to function is_array\\(\\) with array\\<string, array\\{username\\: string, password\\: string\\}\\> will always evaluate to true\\.$#"
count: 1
path: ../tests/Composer/Test/IO/NullIOTest.php

-
message:
"""
#^Call to deprecated method getRawData\\(\\) of class Composer\\\\InstalledVersions\\:
Use getAllRawData\\(\\) instead which returns all datasets for all autoloaders present in the process\\. getRawData only returns the first dataset loaded, which may not be what you expect\\.$#
"""
message: """
#^Call to deprecated method getRawData\\(\\) of class Composer\\\\InstalledVersions\\:
Use getAllRawData\\(\\) instead which returns all datasets for all autoloaders present in the process\\. getRawData only returns the first dataset loaded, which may not be what you expect\\.$#
"""
count: 1
path: ../tests/Composer/Test/InstalledVersionsTest.php

Expand Down Expand Up @@ -8684,11 +8588,6 @@ parameters:
count: 1
path: ../tests/Composer/Test/Platform/VersionTest.php

-
message: "#^Array \\(array\\<Composer\\\\Package\\\\CompletePackage\\>\\) does not accept Composer\\\\Package\\\\CompleteAliasPackage\\|Composer\\\\Package\\\\CompletePackage\\.$#"
count: 1
path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php

-
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Command…' and Composer\\\\Command\\\\BaseCommand will always evaluate to true\\.$#"
count: 1
Expand Down

0 comments on commit e3d99ca

Please sign in to comment.