From 6c85b875f27185b0e36c35aac98af634be25bdc0 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 3 Nov 2022 21:47:26 +0100 Subject: [PATCH] Update to PHPStan 1.9 --- composer.lock | 72 +++---- phpstan/baseline-8.1.neon | 5 - phpstan/baseline.neon | 191 +----------------- .../Command/BaseDependencyCommand.php | 2 +- src/Composer/Command/CompletionTrait.php | 2 +- src/Composer/Command/ExecCommand.php | 4 +- src/Composer/Command/GlobalCommand.php | 4 +- src/Composer/Command/SearchCommand.php | 2 +- src/Composer/Command/ShowCommand.php | 33 +-- src/Composer/Config.php | 1 + src/Composer/Console/Application.php | 12 +- src/Composer/Console/HtmlOutputFormatter.php | 3 +- src/Composer/Console/Input/InputArgument.php | 4 +- src/Composer/Console/Input/InputOption.php | 4 +- src/Composer/DependencyResolver/Decisions.php | 3 + .../DependencyResolver/LockTransaction.php | 4 +- src/Composer/DependencyResolver/Problem.php | 4 +- src/Composer/DependencyResolver/RuleSet.php | 15 +- src/Composer/DependencyResolver/Solver.php | 2 +- .../EventDispatcher/EventDispatcher.php | 4 +- src/Composer/IO/BufferIO.php | 2 + src/Composer/Json/JsonFormatter.php | 2 + src/Composer/Json/JsonManipulator.php | 3 +- src/Composer/Package/Loader/ArrayLoader.php | 2 +- .../Loader/InvalidPackageException.php | 12 +- .../Package/Loader/ValidatingArrayLoader.php | 8 +- src/Composer/Package/Package.php | 6 +- src/Composer/Package/PackageInterface.php | 10 +- src/Composer/Package/RootPackage.php | 2 +- src/Composer/Package/RootPackageInterface.php | 4 +- .../Package/Version/VersionGuesser.php | 2 +- .../Repository/ComposerRepository.php | 4 +- .../Repository/CompositeRepository.php | 2 +- src/Composer/Repository/RepositoryUtils.php | 2 +- src/Composer/Repository/VcsRepository.php | 2 +- src/Composer/Util/Bitbucket.php | 3 + src/Composer/Util/Filesystem.php | 1 + src/Composer/Util/Platform.php | 2 + src/Composer/Util/ProcessExecutor.php | 2 + src/Composer/Util/RemoteFilesystem.php | 4 +- src/Composer/Util/Url.php | 1 + .../DependencyResolver/PoolBuilderTest.php | 2 +- .../Composer/Test/Mock/HttpDownloaderMock.php | 8 +- .../Package/Version/VersionGuesserTest.php | 16 ++ .../Test/Repository/Vcs/GitHubDriverTest.php | 4 + tests/Composer/Test/TestCase.php | 1 + tests/Composer/Test/Util/TlsHelperTest.php | 1 + 47 files changed, 169 insertions(+), 310 deletions(-) diff --git a/composer.lock b/composer.lock index af4fdb69f..f144b2bf9 100644 --- a/composer.lock +++ b/composer.lock @@ -226,16 +226,16 @@ }, { "name": "composer/pcre", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "c8e9d27cfc5ed22643c19c160455b473ffd8aabe" + "reference": "562ca94029b37bb04205e2abb43be5550d2945d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/c8e9d27cfc5ed22643c19c160455b473ffd8aabe", - "reference": "c8e9d27cfc5ed22643c19c160455b473ffd8aabe", + "url": "https://api.github.com/repos/composer/pcre/zipball/562ca94029b37bb04205e2abb43be5550d2945d7", + "reference": "562ca94029b37bb04205e2abb43be5550d2945d7", "shasum": "" }, "require": { @@ -277,7 +277,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/2.0.0" + "source": "https://github.com/composer/pcre/tree/2.0.1" }, "funding": [ { @@ -293,7 +293,7 @@ "type": "tidelift" } ], - "time": "2022-02-25T20:05:29+00:00" + "time": "2022-11-03T15:56:01+00:00" }, { "name": "composer/semver", @@ -941,16 +941,16 @@ }, { "name": "symfony/console", - "version": "v5.4.14", + "version": "v5.4.15", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "984ea2c0f45f42dfed01d2f3987b187467c4b16d" + "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/984ea2c0f45f42dfed01d2f3987b187467c4b16d", - "reference": "984ea2c0f45f42dfed01d2f3987b187467c4b16d", + "url": "https://api.github.com/repos/symfony/console/zipball/ea59bb0edfaf9f28d18d8791410ee0355f317669", + "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669", "shasum": "" }, "require": { @@ -1020,7 +1020,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.14" + "source": "https://github.com/symfony/console/tree/v5.4.15" }, "funding": [ { @@ -1036,7 +1036,7 @@ "type": "tidelift" } ], - "time": "2022-10-07T08:01:20+00:00" + "time": "2022-10-26T21:41:52+00:00" }, { "name": "symfony/deprecation-contracts", @@ -1950,16 +1950,16 @@ }, { "name": "symfony/string", - "version": "v5.4.14", + "version": "v5.4.15", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "089e7237497fae7a9c404d0c3aeb8db3254733e4" + "reference": "571334ce9f687e3e6af72db4d3b2a9431e4fd9ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/089e7237497fae7a9c404d0c3aeb8db3254733e4", - "reference": "089e7237497fae7a9c404d0c3aeb8db3254733e4", + "url": "https://api.github.com/repos/symfony/string/zipball/571334ce9f687e3e6af72db4d3b2a9431e4fd9ed", + "reference": "571334ce9f687e3e6af72db4d3b2a9431e4fd9ed", "shasum": "" }, "require": { @@ -2016,7 +2016,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.14" + "source": "https://github.com/symfony/string/tree/v5.4.15" }, "funding": [ { @@ -2038,16 +2038,16 @@ "packages-dev": [ { "name": "phpstan/phpstan", - "version": "1.8.11", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "46e223dd68a620da18855c23046ddb00940b4014" + "reference": "e08de53a5eec983de78a787a88e72518cf8fe43a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", - "reference": "46e223dd68a620da18855c23046ddb00940b4014", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e08de53a5eec983de78a787a88e72518cf8fe43a", + "reference": "e08de53a5eec983de78a787a88e72518cf8fe43a", "shasum": "" }, "require": { @@ -2077,7 +2077,7 @@ ], "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.8.11" + "source": "https://github.com/phpstan/phpstan/tree/1.9.0" }, "funding": [ { @@ -2093,7 +2093,7 @@ "type": "tidelift" } ], - "time": "2022-10-24T15:45:13+00:00" + "time": "2022-11-03T07:26:48+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -2147,21 +2147,21 @@ }, { "name": "phpstan/phpstan-phpunit", - "version": "1.1.3", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "6b93db7fae6d6f3e81a5b4297f93af6fe4146785" + "reference": "dea1f87344c6964c607d9076dee42d891f3923f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6b93db7fae6d6f3e81a5b4297f93af6fe4146785", - "reference": "6b93db7fae6d6f3e81a5b4297f93af6fe4146785", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/dea1f87344c6964c607d9076dee42d891f3923f0", + "reference": "dea1f87344c6964c607d9076dee42d891f3923f0", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.8.0" + "phpstan/phpstan": "^1.8.11" }, "conflict": { "phpunit/phpunit": "<7.0" @@ -2193,9 +2193,9 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.1.3" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.2.2" }, - "time": "2022-10-24T11:38:17+00:00" + "time": "2022-10-28T10:23:07+00:00" }, { "name": "phpstan/phpstan-strict-rules", @@ -2247,16 +2247,16 @@ }, { "name": "phpstan/phpstan-symfony", - "version": "1.2.14", + "version": "1.2.15", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-symfony.git", - "reference": "f7dd737329504115adaa987697a759a66dd2ee8a" + "reference": "7210072b7fd83bf62eb5f889d4da70b80c07f04c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/f7dd737329504115adaa987697a759a66dd2ee8a", - "reference": "f7dd737329504115adaa987697a759a66dd2ee8a", + "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/7210072b7fd83bf62eb5f889d4da70b80c07f04c", + "reference": "7210072b7fd83bf62eb5f889d4da70b80c07f04c", "shasum": "" }, "require": { @@ -2312,9 +2312,9 @@ "description": "Symfony Framework extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-symfony/issues", - "source": "https://github.com/phpstan/phpstan-symfony/tree/1.2.14" + "source": "https://github.com/phpstan/phpstan-symfony/tree/1.2.15" }, - "time": "2022-10-05T11:19:29+00:00" + "time": "2022-11-03T15:03:30+00:00" }, { "name": "symfony/phpunit-bridge", diff --git a/phpstan/baseline-8.1.neon b/phpstan/baseline-8.1.neon index aa6eae223..085b10dd7 100644 --- a/phpstan/baseline-8.1.neon +++ b/phpstan/baseline-8.1.neon @@ -10,11 +10,6 @@ parameters: count: 1 path: ../src/Composer/Autoload/ClassLoader.php - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\|null given\\.$#" - count: 2 - path: ../src/Composer/Command/BaseDependencyCommand.php - - message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#" count: 1 diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 1e053293d..7fc49702e 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -5,11 +5,6 @@ parameters: count: 1 path: ../src/Composer/Advisory/Auditor.php - - - message: "#^Binary operation \"\\.\" between non\\-falsy\\-string and array\\|string\\|null results in an error\\.$#" - count: 1 - path: ../src/Composer/Autoload/AutoloadGenerator.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 10 @@ -215,11 +210,6 @@ parameters: count: 3 path: ../src/Composer/Command/BaseDependencyCommand.php - - - message: "#^Offset int does not exist on array\\\\|null\\.$#" - count: 2 - path: ../src/Composer/Command/BaseDependencyCommand.php - - message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Package\\\\BasePackage\\|null given\\.$#" count: 1 @@ -245,11 +235,6 @@ parameters: count: 1 path: ../src/Composer/Command/BaseDependencyCommand.php - - - message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\\\|null given\\.$#" - count: 2 - path: ../src/Composer/Command/BaseDependencyCommand.php - - message: "#^Parameter \\#2 \\$commandName of class Composer\\\\Plugin\\\\CommandEvent constructor expects string, string\\|null given\\.$#" count: 1 @@ -640,11 +625,6 @@ parameters: count: 1 path: ../src/Composer/Command/RunScriptCommand.php - - - message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#" - count: 1 - path: ../src/Composer/Command/RunScriptCommand.php - - message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#" count: 1 @@ -670,11 +650,6 @@ parameters: count: 1 path: ../src/Composer/Command/SearchCommand.php - - - message: "#^Only booleans are allowed in &&, array\\\\> given on the left side\\.$#" - count: 1 - path: ../src/Composer/Command/SearchCommand.php - - message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Composer\\|null given\\.$#" count: 1 @@ -755,16 +730,6 @@ parameters: count: 1 path: ../src/Composer/Command/ShowCommand.php - - - message: "#^Method Composer\\\\Command\\\\ShowCommand\\:\\:appendAutoload\\(\\) should return array\\\\|string\\|null\\> but returns array\\\\|string\\>\\|string\\>\\|string\\|null\\>\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - - - message: "#^Method Composer\\\\Command\\\\ShowCommand\\:\\:appendLicenses\\(\\) should return array\\\\|string\\|null\\> but returns array\\\\|string\\>\\|string\\|null\\>\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - message: "#^Method Composer\\\\Command\\\\ShowCommand\\:\\:getPackage\\(\\) should return array\\{Composer\\\\Package\\\\CompletePackageInterface\\|null, array\\\\} but returns array\\{Composer\\\\Package\\\\BasePackage\\|int\\|null, array\\\\}\\.$#" count: 1 @@ -865,11 +830,6 @@ parameters: count: 2 path: ../src/Composer/Command/ShowCommand.php - - - message: "#^Only booleans are allowed in an if condition, array\\\\|string\\>\\> given\\.$#" - count: 2 - path: ../src/Composer/Command/ShowCommand.php - - message: "#^Only booleans are allowed in an if condition, array\\ given\\.$#" count: 4 @@ -900,11 +860,6 @@ parameters: count: 2 path: ../src/Composer/Command/ShowCommand.php - - - message: "#^Parameter \\#1 \\$json of method Composer\\\\Command\\\\ShowCommand\\:\\:appendAutoload\\(\\) expects array\\\\|string\\|null\\>, array\\\\|string\\|false\\|null\\> given\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - message: "#^Parameter \\#1 \\$package of method Composer\\\\Repository\\\\CompositeRepository\\:\\:hasPackage\\(\\) expects Composer\\\\Package\\\\PackageInterface, Composer\\\\Package\\\\BasePackage\\|int given\\.$#" count: 1 @@ -1275,11 +1230,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/Decisions.php - - - message: "#^Offset 0 does not exist on array\\{int, Composer\\\\DependencyResolver\\\\Rule\\}\\|null\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Decisions.php - - message: "#^Only booleans are allowed in a ternary operator condition, Composer\\\\DependencyResolver\\\\Pool\\|null given\\.$#" count: 1 @@ -1490,11 +1440,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/Rule.php - - - message: "#^Method Composer\\\\DependencyResolver\\\\RuleSet\\:\\:getTypes\\(\\) should return array\\{0, 1, 4\\} but returns array\\\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/RuleSet.php - - message: "#^Only booleans are allowed in &&, Composer\\\\DependencyResolver\\\\Pool\\|null given on the right side\\.$#" count: 1 @@ -1575,11 +1520,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/Solver.php - - - message: "#^Only booleans are allowed in a negated boolean, int\\|null given\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Solver.php - - message: "#^Only booleans are allowed in an if condition, Composer\\\\DependencyResolver\\\\Rule\\|null given\\.$#" count: 1 @@ -1611,7 +1551,7 @@ parameters: path: ../src/Composer/DependencyResolver/Solver.php - - message: "#^Parameter \\#1 \\$literals of class Composer\\\\DependencyResolver\\\\GenericRule constructor expects array\\, array\\ given\\.$#" + message: "#^Parameter \\#1 \\$literals of class Composer\\\\DependencyResolver\\\\GenericRule constructor expects list\\, non\\-empty\\-list\\ given\\.$#" count: 1 path: ../src/Composer/DependencyResolver/Solver.php @@ -2382,7 +2322,7 @@ parameters: - message: "#^Only booleans are allowed in a negated boolean, array\\ given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Installer.php - @@ -2402,7 +2342,7 @@ parameters: - message: "#^Only booleans are allowed in an if condition, array\\ given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Installer.php - @@ -2555,26 +2495,11 @@ parameters: count: 1 path: ../src/Composer/Installer/InstallationManager.php - - - message: "#^Parameter \\#1 \\$onFulfilled of method React\\\\Promise\\\\PromiseInterface\\:\\:then\\(\\) expects \\(callable\\(\\)\\: mixed\\)\\|null, React\\\\Promise\\\\PromiseInterface given\\.$#" - count: 1 - path: ../src/Composer/Installer/InstallationManager.php - - message: "#^Parameter \\#2 \\$offset of function array_splice expects int, int\\|string given\\.$#" count: 1 path: ../src/Composer/Installer/InstallationManager.php - - - message: "#^Parameter \\#3 \\$cleanupPromises of method Composer\\\\Installer\\\\InstallationManager\\:\\:executeBatch\\(\\) expects array\\, array\\<\\(Closure\\)\\|React\\\\Promise\\\\PromiseInterface\\> given\\.$#" - count: 1 - path: ../src/Composer/Installer/InstallationManager.php - - - - message: "#^Trying to invoke React\\\\Promise\\\\PromiseInterface but it might not be a callable\\.$#" - count: 1 - path: ../src/Composer/Installer/InstallationManager.php - - message: "#^Variable method call on \\$this\\(Composer\\\\Installer\\\\InstallationManager\\)\\.$#" count: 2 @@ -2955,11 +2880,6 @@ parameters: count: 1 path: ../src/Composer/Package/Loader/JsonLoader.php - - - message: "#^Instanceof between Composer\\\\Package\\\\RootPackage and Composer\\\\Package\\\\RootPackage will always evaluate to true\\.$#" - count: 1 - path: ../src/Composer/Package/Loader/RootPackageLoader.php - - message: "#^Only booleans are allowed in an elseif condition, string\\|null given\\.$#" count: 1 @@ -3150,11 +3070,6 @@ parameters: count: 3 path: ../src/Composer/Package/Version/VersionGuesser.php - - - message: "#^Offset 'feature_pretty…' does not exist on array\\{version\\: non\\-falsy\\-string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\: non\\-falsy\\-string, feature_pretty_version\\?\\: string\\|null\\}\\.$#" - count: 1 - path: ../src/Composer/Package/Version/VersionGuesser.php - - message: "#^Only booleans are allowed in &&, string given on the left side\\.$#" count: 2 @@ -3515,11 +3430,6 @@ parameters: count: 3 path: ../src/Composer/Repository/CompositeRepository.php - - - message: "#^Only booleans are allowed in a ternary operator condition, array\\\\>\\> given\\.$#" - count: 1 - path: ../src/Composer/Repository/CompositeRepository.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\\\>\\> given\\.$#" count: 1 @@ -4163,11 +4073,6 @@ parameters: count: 1 path: ../src/Composer/Repository/VcsRepository.php - - - message: "#^Only booleans are allowed in &&, array\\ given on the right side\\.$#" - count: 1 - path: ../src/Composer/Repository/VcsRepository.php - - message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Package\\\\Loader\\\\LoaderInterface\\|null given\\.$#" count: 1 @@ -4303,11 +4208,6 @@ parameters: count: 1 path: ../src/Composer/Util/Bitbucket.php - - - message: "#^Offset 'access_token' does not exist on array\\{access_token\\: string, expires_in\\?\\: int\\}\\|null\\.$#" - count: 1 - path: ../src/Composer/Util/Bitbucket.php - - message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" count: 2 @@ -5363,11 +5263,6 @@ parameters: count: 1 path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php - - - message: "#^Method Composer\\\\Test\\\\DependencyResolver\\\\PoolBuilderTest\\:\\:getPackageResultSet\\(\\) should return array\\ but returns array\\\\|int\\<1, max\\>\\|string\\>\\.$#" - count: 1 - path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php - - message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" count: 2 @@ -5686,36 +5581,6 @@ parameters: count: 1 path: ../tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php - - - message: "#^Offset 'commit' does not exist on array\\{version\\: string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\}\\|null\\.$#" - count: 6 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - - - message: "#^Offset 'feature_pretty…' does not exist on array\\{version\\: string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\}\\|null\\.$#" - count: 2 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - - - message: "#^Offset 'feature_version' does not exist on array\\{version\\: string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\}\\|null\\.$#" - count: 2 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - - - message: "#^Offset 'pretty_version' does not exist on array\\{version\\: string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\}\\|null\\.$#" - count: 5 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - - - message: "#^Offset 'version' does not exist on array\\{version\\: string, commit\\: string\\|null, pretty_version\\: string\\|null, feature_version\\?\\: string\\|null, feature_pretty_version\\?\\: string\\|null\\}\\|null\\.$#" - count: 14 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - - - message: "#^Parameter \\#2 \\$array of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayNotHasKey\\(\\) expects array\\|ArrayAccess, array\\\\|null given\\.$#" - count: 4 - path: ../tests/Composer/Test/Package/Version/VersionGuesserTest.php - - message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" count: 1 @@ -5736,21 +5601,6 @@ parameters: count: 1 path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Plugin…' and Composer\\\\Plugin\\\\Capability\\\\CommandProvider will always evaluate to true\\.$#" - count: 1 - path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Plugin…' and Composer\\\\Test\\\\Plugin\\\\Mock\\\\Capability will always evaluate to true\\.$#" - count: 1 - path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Test…' and Composer\\\\Test\\\\Plugin\\\\Mock\\\\Capability will always evaluate to true\\.$#" - count: 1 - path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - message: "#^Parameter \\#2 \\$capabilityClassName of method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\) expects class\\-string\\, string given\\.$#" count: 2 @@ -5801,31 +5651,11 @@ parameters: count: 1 path: ../tests/Composer/Test/Repository/PathRepositoryTest.php - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Repository…' and Composer\\\\Repository\\\\FilterRepository will always evaluate to true\\.$#" - count: 1 - path: ../tests/Composer/Test/Repository/RepositoryManagerTest.php - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Repository…' and Composer\\\\Repository\\\\RepositoryInterface will always evaluate to true\\.$#" count: 1 path: ../tests/Composer/Test/Repository/RepositoryManagerTest.php - - - message: "#^Offset 'reference' does not exist on array\\{type\\: string, url\\: string, reference\\: string, shasum\\: string\\}\\|null\\.$#" - count: 4 - path: ../tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php - - - - message: "#^Offset 'type' does not exist on array\\{type\\: string, url\\: string, reference\\: string, shasum\\: string\\}\\|null\\.$#" - count: 4 - path: ../tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php - - - - message: "#^Offset 'url' does not exist on array\\{type\\: string, url\\: string, reference\\: string, shasum\\: string\\}\\|null\\.$#" - count: 4 - path: ../tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php - - message: "#^Parameter \\#1 \\$objectOrValue of method ReflectionProperty\\:\\:setValue\\(\\) expects object\\|null, object\\|string given\\.$#" count: 1 @@ -5836,11 +5666,6 @@ parameters: count: 1 path: ../tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\) with array\\<'0\\.6\\.0'\\|'1\\.0\\.0'\\|'1\\.0\\.x\\-dev'\\|'1\\.1\\.x\\-dev'\\|'9999999\\-dev'\\|'dev\\-feature\\-b'\\|'dev\\-feature/a\\-1\\.0\\-B'\\|'dev\\-master', true\\> and literal\\-string&non\\-falsy\\-string will always evaluate to false\\.$#" - count: 1 - path: ../tests/Composer/Test/Repository/VcsRepositoryTest.php - - message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" count: 1 @@ -5876,6 +5701,11 @@ parameters: count: 1 path: ../tests/Composer/Test/TestCase.php + - + message: "#^Cannot access an offset on array\\\\>\\|false\\.$#" + count: 1 + path: ../tests/Composer/Test/Util/GitTest.php + - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Composer\\\\\\\\Util\\\\\\\\Http…' and Composer\\\\Util\\\\Http\\\\ProxyManager will always evaluate to true\\.$#" count: 1 @@ -5971,11 +5801,6 @@ parameters: count: 2 path: ../tests/Composer/Test/Util/TlsHelperTest.php - - - message: "#^Offset 'cn' does not exist on array\\{cn\\: string, san\\: array\\\\}\\|null\\.$#" - count: 1 - path: ../tests/Composer/Test/Util/TlsHelperTest.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\ given\\.$#" count: 1 diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index 805352ea2..82662093a 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -41,7 +41,7 @@ abstract class BaseDependencyCommand extends BaseCommand protected const OPTION_RECURSIVE = 'recursive'; protected const OPTION_TREE = 'tree'; - /** @var ?string[] */ + /** @var string[] */ protected $colors; /** diff --git a/src/Composer/Command/CompletionTrait.php b/src/Composer/Command/CompletionTrait.php index 1b936263e..89c6b68e5 100644 --- a/src/Composer/Command/CompletionTrait.php +++ b/src/Composer/Command/CompletionTrait.php @@ -38,7 +38,7 @@ trait CompletionTrait /** * Suggestion values for "prefer-install" option * - * @return string[] + * @return list */ private function suggestPreferInstall(): array { diff --git a/src/Composer/Command/ExecCommand.php b/src/Composer/Command/ExecCommand.php index 7e281bb2c..edec5c6db 100644 --- a/src/Composer/Command/ExecCommand.php +++ b/src/Composer/Command/ExecCommand.php @@ -63,7 +63,7 @@ EOT } $io = $this->getIO(); - /** @var string $binary */ + /** @var int $binary */ $binary = $io->select( 'Binary to run: ', $binaries, @@ -123,7 +123,7 @@ EOT } /** - * @return string[] + * @return list */ private function getBinaries(bool $forDisplay): array { diff --git a/src/Composer/Command/GlobalCommand.php b/src/Composer/Command/GlobalCommand.php index 1d8996624..c6fc7fe7a 100644 --- a/src/Composer/Command/GlobalCommand.php +++ b/src/Composer/Command/GlobalCommand.php @@ -33,9 +33,9 @@ class GlobalCommand extends BaseCommand { $application = $this->getApplication(); if ($input->mustSuggestArgumentValuesFor('command-name')) { - $suggestions->suggestValues(array_filter(array_map(static function (Command $command) { + $suggestions->suggestValues(array_values(array_filter(array_map(static function (Command $command) { return $command->isHidden() ? null : $command->getName(); - }, $application->all()))); + }, $application->all())))); return; } diff --git a/src/Composer/Command/SearchCommand.php b/src/Composer/Command/SearchCommand.php index 955251731..61f0f95eb 100644 --- a/src/Composer/Command/SearchCommand.php +++ b/src/Composer/Command/SearchCommand.php @@ -95,7 +95,7 @@ EOT $results = $repos->search($query, $mode, $type); - if ($results && $format === 'text') { + if (\count($results) > 0 && $format === 'text') { $width = $this->getTerminalWidth(); $nameLength = 0; diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index f90b8160b..8257d83d2 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -55,6 +55,9 @@ use Symfony\Component\Console\Output\OutputInterface; * @author Jordi Boggiano * @author Jérémy Romey * @author Mihai Plasoianu + * + * @phpstan-import-type AutoloadRules from PackageInterface + * @phpstan-type JsonStructure array|AutoloadRules> */ class ShowCommand extends BaseCommand { @@ -820,7 +823,7 @@ EOT } } - if ($package->getAutoload()) { + if (\count($package->getAutoload()) > 0) { $io->write("\nautoload"); $autoloadConfig = $package->getAutoload(); foreach ($autoloadConfig as $type => $autoloads) { @@ -955,9 +958,9 @@ EOT } if ($installedRepo->hasPackage($package)) { - $json['path'] = realpath($this->requireComposer()->getInstallationManager()->getInstallPath($package)); - if ($json['path'] === false) { - unset($json['path']); + $path = realpath($this->requireComposer()->getInstallationManager()->getInstallPath($package)); + if ($path !== false) { + $json['path'] = $path; } } @@ -985,9 +988,9 @@ EOT } /** - * @param array $json + * @param JsonStructure $json * @param array $versions - * @return array + * @return JsonStructure */ private function appendVersions(array $json, array $versions): array { @@ -999,8 +1002,8 @@ EOT } /** - * @param array $json - * @return array + * @param JsonStructure $json + * @return JsonStructure */ private function appendLicenses(array $json, CompletePackageInterface $package): array { @@ -1026,12 +1029,12 @@ EOT } /** - * @param array $json - * @return array + * @param JsonStructure $json + * @return JsonStructure */ private function appendAutoload(array $json, CompletePackageInterface $package): array { - if ($package->getAutoload()) { + if (\count($package->getAutoload()) > 0) { $autoload = []; foreach ($package->getAutoload() as $type => $autoloads) { @@ -1059,8 +1062,8 @@ EOT } /** - * @param array $json - * @return array + * @param JsonStructure $json + * @return JsonStructure */ private function appendLinks(array $json, CompletePackageInterface $package): array { @@ -1072,8 +1075,8 @@ EOT } /** - * @param array $json - * @return array + * @param JsonStructure $json + * @return JsonStructure */ private function appendLink(array $json, CompletePackageInterface $package, string $linkType): array { diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 8d132bb7c..38e87e0a5 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -496,6 +496,7 @@ class Config } return Preg::replaceCallback('#\{\$(.+)\}#', function ($match) use ($flags) { + assert(is_string($match[1])); return $this->get($match[1], $flags); }, $value); } diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 872670f95..54353fa38 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -403,17 +403,7 @@ class Application extends BaseApplication $this->renderThrowable($e, $output); } - $exitCode = $e->getCode(); - if (is_numeric($exitCode)) { - $exitCode = (int) $exitCode; - if (0 === $exitCode) { - $exitCode = 1; - } - } else { - $exitCode = 1; - } - - return $exitCode; + return max(1, $e->getCode()); } throw $e; diff --git a/src/Composer/Console/HtmlOutputFormatter.php b/src/Composer/Console/HtmlOutputFormatter.php index 84254cc64..af638d605 100644 --- a/src/Composer/Console/HtmlOutputFormatter.php +++ b/src/Composer/Console/HtmlOutputFormatter.php @@ -75,10 +75,11 @@ class HtmlOutputFormatter extends OutputFormatter } /** - * @param string[] $matches + * @param array $matches */ private function formatHtml(array $matches): string { + assert(is_string($matches[1])); $out = 'rules as $type => $rules) { - $string .= str_pad(self::$types[$type], 8, ' ') . ": "; + $string .= str_pad(self::TYPES[$type], 8, ' ') . ": "; foreach ($rules as $rule) { $string .= ($repositorySet && $request && $pool ? $rule->getPrettyString($repositorySet, $request, $pool, $isVerbose) : $rule)."\n"; } diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 2d9e6bad4..ccfb6ebe5 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -475,7 +475,7 @@ class Solver $why = \count($this->learnedPool) - 1; - if (!$learnedLiterals[0]) { + if (null === $learnedLiterals[0]) { throw new SolverBugException( "Did not find a learnable literal in analyzed rule $analyzedRule." ); diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 26ea4aa30..9a94c3bcb 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -342,7 +342,7 @@ class EventDispatcher $pathAndArgs = substr($exec, 5); if (Platform::isWindows()) { $pathAndArgs = Preg::replaceCallback('{^\S+}', static function ($path) { - return str_replace('/', '\\', $path[0]); + return str_replace('/', '\\', (string) $path[0]); }, $pathAndArgs); } // match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it @@ -364,6 +364,8 @@ class EventDispatcher if (Platform::isWindows()) { $exec = Preg::replaceCallback('{^\S+}', static function ($path) { + assert(is_string($path[0])); + return str_replace('/', '\\', $path[0]); }, $exec); } diff --git a/src/Composer/IO/BufferIO.php b/src/Composer/IO/BufferIO.php index f6f208d96..0404287a0 100644 --- a/src/Composer/IO/BufferIO.php +++ b/src/Composer/IO/BufferIO.php @@ -52,6 +52,8 @@ class BufferIO extends ConsoleIO $output = stream_get_contents($this->output->getStream()); $output = Preg::replaceCallback("{(?<=^|\n|\x08)(.+?)(\x08+)}", static function ($matches): string { + assert(is_string($matches[1])); + assert(is_string($matches[2])); $pre = strip_tags($matches[1]); if (strlen($pre) === strlen($matches[2])) { diff --git a/src/Composer/Json/JsonFormatter.php b/src/Composer/Json/JsonFormatter.php index 633d2c399..006365675 100644 --- a/src/Composer/Json/JsonFormatter.php +++ b/src/Composer/Json/JsonFormatter.php @@ -68,6 +68,8 @@ class JsonFormatter if ($unescapeUnicode && function_exists('mb_convert_encoding')) { // https://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha $buffer = Preg::replaceCallback('/(\\\\+)u([0-9a-f]{4})/i', static function ($match) { + assert(is_string($match[1])); + assert(is_string($match[2])); $l = strlen($match[1]); if ($l % 2) { diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index e62fa6972..6458ceb07 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -261,7 +261,7 @@ class JsonManipulator $childRegex = '{'.self::$DEFINES.'(?P"'.preg_quote($name).'"\s*:\s*)(?P(?&json))(?P,?)}x'; if (Preg::isMatch($childRegex, $children, $matches)) { $children = Preg::replaceCallback($childRegex, function ($matches) use ($subName, $value): string { - if ($subName !== null) { + if ($subName !== null && is_string($matches['content'])) { $curVal = json_decode($matches['content'], true); if (!is_array($curVal)) { $curVal = []; @@ -410,6 +410,7 @@ class JsonManipulator } $this->contents = Preg::replaceCallback($nodeRegex, function ($matches) use ($name, $subName, $childrenClean): string { + assert(is_string($matches['content'])); if ($subName !== null) { $curVal = json_decode($matches['content'], true); unset($curVal[$name][$subName]); diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 47b314e33..d33f1bc3f 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -75,7 +75,7 @@ class ArrayLoader implements LoaderInterface } /** - * @param list> $versions + * @param array> $versions * * @return list */ diff --git a/src/Composer/Package/Loader/InvalidPackageException.php b/src/Composer/Package/Loader/InvalidPackageException.php index d021564ad..51f0db895 100644 --- a/src/Composer/Package/Loader/InvalidPackageException.php +++ b/src/Composer/Package/Loader/InvalidPackageException.php @@ -17,16 +17,16 @@ namespace Composer\Package\Loader; */ class InvalidPackageException extends \Exception { - /** @var string[] */ + /** @var list */ private $errors; - /** @var string[] */ + /** @var list */ private $warnings; /** @var mixed[] package config */ private $data; /** - * @param string[] $errors - * @param string[] $warnings + * @param list $errors + * @param list $warnings * @param mixed[] $data */ public function __construct(array $errors, array $warnings, array $data) @@ -46,7 +46,7 @@ class InvalidPackageException extends \Exception } /** - * @return string[] + * @return list */ public function getErrors(): array { @@ -54,7 +54,7 @@ class InvalidPackageException extends \Exception } /** - * @return string[] + * @return list */ public function getWarnings(): array { diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 45cf21371..396ab23ae 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -32,9 +32,9 @@ class ValidatingArrayLoader implements LoaderInterface private $loader; /** @var VersionParser */ private $versionParser; - /** @var string[] */ + /** @var list */ private $errors; - /** @var string[] */ + /** @var list */ private $warnings; /** @var mixed[] */ private $config; @@ -428,7 +428,7 @@ class ValidatingArrayLoader implements LoaderInterface } /** - * @return string[] + * @return list */ public function getWarnings(): array { @@ -436,7 +436,7 @@ class ValidatingArrayLoader implements LoaderInterface } /** - * @return string[] + * @return list */ public function getErrors(): array { diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index e7b94766f..295bbd249 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -38,7 +38,7 @@ class Package extends BasePackage protected $sourceUrl; /** @var ?string */ protected $sourceReference; - /** @var ?array */ + /** @var ?list */ protected $sourceMirrors; /** @var ?non-empty-string */ protected $distType; @@ -48,7 +48,7 @@ class Package extends BasePackage protected $distReference; /** @var ?string */ protected $distSha1Checksum; - /** @var ?array */ + /** @var ?list */ protected $distMirrors; /** @var string */ protected $version; @@ -658,7 +658,7 @@ class Package extends BasePackage /** * @param mixed[]|null $mirrors * - * @return non-empty-string[] + * @return list * * @phpstan-param list|null $mirrors */ diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index fc2470e2c..4d874ef12 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -127,7 +127,7 @@ interface PackageInterface /** * Returns the repository urls of this package including mirrors, e.g. git://github.com/naderman/composer.git * - * @return string[] + * @return list */ public function getSourceUrls(): array; @@ -141,12 +141,12 @@ interface PackageInterface /** * Returns the source mirrors of this package * - * @return ?array + * @return ?list */ public function getSourceMirrors(): ?array; /** - * @param null|array $mirrors + * @param null|list $mirrors */ public function setSourceMirrors(?array $mirrors): void; @@ -188,12 +188,12 @@ interface PackageInterface /** * Returns the dist mirrors of this package * - * @return ?array + * @return ?list */ public function getDistMirrors(): ?array; /** - * @param null|array $mirrors + * @param null|list $mirrors */ public function setDistMirrors(?array $mirrors): void; diff --git a/src/Composer/Package/RootPackage.php b/src/Composer/Package/RootPackage.php index 7f2d65676..e1305426f 100644 --- a/src/Composer/Package/RootPackage.php +++ b/src/Composer/Package/RootPackage.php @@ -31,7 +31,7 @@ class RootPackage extends CompletePackage implements RootPackageInterface protected $config = []; /** @var array Map of package name to reference/commit hash */ protected $references = []; - /** @var array */ + /** @var list */ protected $aliases = []; /** diff --git a/src/Composer/Package/RootPackageInterface.php b/src/Composer/Package/RootPackageInterface.php index 579a95dc2..4adad6c8b 100644 --- a/src/Composer/Package/RootPackageInterface.php +++ b/src/Composer/Package/RootPackageInterface.php @@ -27,7 +27,7 @@ interface RootPackageInterface extends CompletePackageInterface /** * Returns a set of package names and their aliases * - * @return array + * @return list */ public function getAliases(): array; @@ -151,7 +151,7 @@ interface RootPackageInterface extends CompletePackageInterface /** * Set the aliases * - * @param array $aliases + * @param list $aliases */ public function setAliases(array $aliases): void; diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 1ccc32b29..54e403410 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -31,7 +31,7 @@ use Symfony\Component\Process\Process; * @author Jordi Boggiano * @author Samuel Roze * - * @phpstan-type Version array{version: string, commit: string|null, pretty_version: string|null, feature_version?: string|null, feature_pretty_version?: string|null} + * @phpstan-type Version array{version: string, commit: string|null, pretty_version: string|null}|array{version: string, commit: string|null, pretty_version: string|null, feature_version: string|null, feature_pretty_version: string|null} */ class VersionGuesser { diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index dc0435973..78d9e0bd9 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -95,9 +95,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito private $allowSslDowngrade = false; /** @var ?EventDispatcher */ private $eventDispatcher; - /** @var ?array> */ + /** @var ?array> */ private $sourceMirrors; - /** @var ?array */ + /** @var ?list */ private $distMirrors; /** @var bool */ private $degradedMode = false; diff --git a/src/Composer/Repository/CompositeRepository.php b/src/Composer/Repository/CompositeRepository.php index 08af5ea60..8ee53261e 100644 --- a/src/Composer/Repository/CompositeRepository.php +++ b/src/Composer/Repository/CompositeRepository.php @@ -133,7 +133,7 @@ class CompositeRepository implements RepositoryInterface $matches[] = $repository->search($query, $mode, $type); } - return $matches ? array_merge(...$matches) : []; + return \count($matches) > 0 ? array_merge(...$matches) : []; } /** diff --git a/src/Composer/Repository/RepositoryUtils.php b/src/Composer/Repository/RepositoryUtils.php index 13de4e2ce..62e1c5b0f 100644 --- a/src/Composer/Repository/RepositoryUtils.php +++ b/src/Composer/Repository/RepositoryUtils.php @@ -28,7 +28,7 @@ class RepositoryUtils * * @template T of PackageInterface * @param array $packages - * @param array $bucket Do not pass this in, only used to avoid recursion with circular deps + * @param list $bucket Do not pass this in, only used to avoid recursion with circular deps * @return list */ public static function filterRequiredPackages(array $packages, PackageInterface $requirer, array $bucket = []): array diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 75b138b79..d110c38d4 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -383,7 +383,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $packageData = $this->preProcess($driver, $data, $identifier); $package = $this->loader->load($packageData); - if ($this->loader instanceof ValidatingArrayLoader && $this->loader->getWarnings()) { + if ($this->loader instanceof ValidatingArrayLoader && \count($this->loader->getWarnings()) > 0) { throw new InvalidPackageException($this->loader->getErrors(), $this->loader->getWarnings(), $packageData); } $this->addPackage($package); diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index e77598df2..f5f2cc9c9 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -226,6 +226,9 @@ class Bitbucket $this->config->getAuthConfigSource()->addConfigSetting('bitbucket-oauth.'.$originUrl, $consumer); } + /** + * @phpstan-assert-if-true array{access_token: string} $this->token + */ private function getTokenFromConfig(string $originUrl): bool { $authConfig = $this->config->get('bitbucket-oauth'); diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 419d62be4..d9f55261b 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -574,6 +574,7 @@ class Filesystem // ensure c: is normalized to C: $prefix = Preg::replaceCallback('{(^|://)[a-z]:$}i', static function (array $m) { + assert(is_string($m[0])); return strtoupper($m[0]); }, $prefix); diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 2bbc61225..2d0c89d88 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -98,6 +98,8 @@ class Platform } return Preg::replaceCallback('#^(\$|(?P%))(?P\w++)(?(percent)%)(?P.*)#', static function ($matches): string { + assert(is_string($matches['var'])); + // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons if (Platform::isWindows() && $matches['var'] === 'HOME') { return (Platform::getEnv('HOME') ?: Platform::getEnv('USERPROFILE')) . $matches['path']; diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index aab99f788..e66b6cc5a 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -415,6 +415,8 @@ class ProcessExecutor $commandString = is_string($command) ? $command : implode(' ', array_map(self::class.'::escape', $command)); $safeCommand = Preg::replaceCallback('{://(?P[^:/\s]+):(?P[^@\s/]+)@}i', static function ($m): string { + assert(is_string($m['user'])); + // if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx) we obfuscate that if (Preg::isMatch('{^([a-f0-9]{12,}|gh[a-z]_[a-zA-Z0-9_]+)$}', $m['user'])) { return '://***:***@'; diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index a490c966f..8abf015a7 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -52,7 +52,7 @@ class RemoteFilesystem private $options = []; /** @var bool */ private $disableTls = false; - /** @var string[] */ + /** @var list */ private $lastHeaders; /** @var bool */ private $storeAuth = false; @@ -159,7 +159,7 @@ class RemoteFilesystem /** * Returns the headers of the last request * - * @return string[] + * @return list */ public function getLastHeaders() { diff --git a/src/Composer/Util/Url.php b/src/Composer/Util/Url.php index 040d17db0..5d703a20d 100644 --- a/src/Composer/Util/Url.php +++ b/src/Composer/Util/Url.php @@ -110,6 +110,7 @@ class Url $url = Preg::replace('{([&?]access_token=)[^&]+}', '$1***', $url); $url = Preg::replaceCallback('{^(?P[a-z0-9]+://)?(?P[^:/\s@]+):(?P[^@\s/]+)@}i', static function ($m): string { + assert(is_string($m['user'])); // if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx) we obfuscate that if (Preg::isMatch('{^([a-f0-9]{12,}|gh[a-z]_[a-zA-Z0-9_]+|github_pat_[a-zA-Z0-9_]+)$}', $m['user'])) { return $m['prefix'].'***:***@'; diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index e6c804454..6c5b3d8e5 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -148,7 +148,7 @@ class PoolBuilderTest extends TestCase /** * @param array $packageIds - * @return string[] + * @return list */ private function getPackageResultSet(Pool $pool, array $packageIds): array { diff --git a/tests/Composer/Test/Mock/HttpDownloaderMock.php b/tests/Composer/Test/Mock/HttpDownloaderMock.php index 5583b1325..538124a1d 100644 --- a/tests/Composer/Test/Mock/HttpDownloaderMock.php +++ b/tests/Composer/Test/Mock/HttpDownloaderMock.php @@ -32,7 +32,7 @@ class HttpDownloaderMock extends HttpDownloader */ private $strict = false; /** - * @var array{status: int, body: string, headers: array} + * @var array{status: int, body: string, headers: list} */ private $defaultHandler = ['status' => 200, 'body' => '', 'headers' => []]; /** @@ -52,9 +52,9 @@ class HttpDownloaderMock extends HttpDownloader } /** - * @param array, status?: int, body?: string, headers?: array}> $expectations + * @param array, status?: int, body?: string, headers?: list}> $expectations * @param bool $strict set to true if you want to provide *all* expected http requests, and not just a subset you are interested in testing - * @param array{status?: int, body?: string, headers?: array} $defaultHandler default URL handler for undefined requests if not in strict mode + * @param array{status?: int, body?: string, headers?: list} $defaultHandler default URL handler for undefined requests if not in strict mode */ public function expects(array $expectations, bool $strict = false, array $defaultHandler = ['status' => 200, 'body' => '', 'headers' => []]): void { @@ -119,7 +119,7 @@ class HttpDownloaderMock extends HttpDownloader } /** - * @param string[] $headers + * @param list $headers * @param non-empty-string $url */ private function respond(string $url, int $status, array $headers, string $body): Response diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 6bc7f03a0..2e59afe6a 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -49,6 +49,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-".$branch, $versionArray['version']); $this->assertEquals("dev-".$branch, $versionArray['pretty_version']); $this->assertEmpty($versionArray['commit']); @@ -72,6 +73,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-master", $versionArray['version']); $this->assertEquals("dev-master", $versionArray['pretty_version']); $this->assertArrayNotHasKey('feature_version', $versionArray); @@ -98,6 +100,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion(['version' => 'self.version'], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-current", $versionArray['version']); $this->assertEquals($anotherCommitHash, $versionArray['commit']); } @@ -124,8 +127,10 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion(['version' => 'self.version', 'non-feature-branches' => ['arbitrary']], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-arbitrary", $versionArray['version']); $this->assertEquals($anotherCommitHash, $versionArray['commit']); + self::assertArrayHasKey('feature_version', $versionArray); $this->assertEquals("dev-feature", $versionArray['feature_version']); $this->assertEquals("dev-feature", $versionArray['feature_pretty_version']); } @@ -152,8 +157,10 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion(['version' => 'self.version', 'non-feature-branches' => ['latest-.*']], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-latest-testing", $versionArray['version']); $this->assertEquals($anotherCommitHash, $versionArray['commit']); + self::assertArrayHasKey('feature_version', $versionArray); $this->assertEquals("dev-feature", $versionArray['feature_version']); $this->assertEquals("dev-feature", $versionArray['feature_pretty_version']); } @@ -176,6 +183,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionArray = $guesser->guessVersion(['version' => 'self.version', 'non-feature-branches' => ['latest-.*']], 'dummy/path'); + self::assertIsArray($versionArray); $this->assertEquals("dev-latest-testing", $versionArray['version']); $this->assertEquals($commitHash, $versionArray['commit']); $this->assertArrayNotHasKey('feature_version', $versionArray); @@ -200,6 +208,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("dev-$commitHash", $versionData['version']); } @@ -221,6 +230,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("dev-$commitHash", $versionData['version']); } @@ -242,6 +252,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("dev-$commitHash", $versionData['version']); } @@ -264,6 +275,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("2.0.5.0-alpha2", $versionData['version']); } @@ -286,6 +298,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals('1.0.0.0', $versionData['version']); $this->assertEquals('1.0.0', $versionData['pretty_version']); } @@ -305,6 +318,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("dev-foo", $versionData['version']); } @@ -323,6 +337,7 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion([], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("1.5.x-dev", $versionData['pretty_version']); $this->assertEquals("1.5.9999999.9999999-dev", $versionData['version']); } @@ -346,6 +361,7 @@ class VersionGuesserTest extends TestCase $config->merge(['repositories' => ['packagist' => false]]); $guesser = new VersionGuesser($config, $process, new VersionParser()); $versionData = $guesser->guessVersion(['version' => 'self.version'], 'dummy/path'); + self::assertIsArray($versionData); $this->assertEquals("1.5.x-dev", $versionData['pretty_version']); $this->assertEquals("1.5.9999999.9999999-dev", $versionData['version']); } diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 707ae7e5e..e023b3538 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -94,6 +94,7 @@ class GitHubDriverTest extends TestCase $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); $dist = $gitHubDriver->getDist($sha); + self::assertIsArray($dist); $this->assertEquals('zip', $dist['type']); $this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']); $this->assertEquals('SOMESHA', $dist['reference']); @@ -136,6 +137,7 @@ class GitHubDriverTest extends TestCase $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); $dist = $gitHubDriver->getDist($sha); + self::assertIsArray($dist); $this->assertEquals('zip', $dist['type']); $this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']); $this->assertEquals($sha, $dist['reference']); @@ -181,6 +183,7 @@ class GitHubDriverTest extends TestCase $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); $dist = $gitHubDriver->getDist($sha); + self::assertIsArray($dist); $this->assertEquals('zip', $dist['type']); $this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']); $this->assertEquals($sha, $dist['reference']); @@ -288,6 +291,7 @@ class GitHubDriverTest extends TestCase $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); $dist = $gitHubDriver->getDist($sha); + self::assertIsArray($dist); $this->assertEquals('zip', $dist['type']); $this->assertEquals('https://api.github.com/repos/composer/packagist/zipball/SOMESHA', $dist['url']); $this->assertEquals($sha, $dist['reference']); diff --git a/tests/Composer/Test/TestCase.php b/tests/Composer/Test/TestCase.php index 9d0aae57a..46daa751d 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -331,6 +331,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { if (Platform::isWindows()) { $cmd = Preg::replaceCallback("/('[^']*')/", static function ($m) { + assert(is_string($m[1])); // Double-quotes are used only when needed $char = (strpbrk($m[1], " \t^&|<>()") !== false || $m[1] === "''") ? '"' : ''; diff --git a/tests/Composer/Test/Util/TlsHelperTest.php b/tests/Composer/Test/Util/TlsHelperTest.php index 58c4cd374..545e49418 100644 --- a/tests/Composer/Test/Util/TlsHelperTest.php +++ b/tests/Composer/Test/Util/TlsHelperTest.php @@ -73,6 +73,7 @@ class TlsHelperTest extends TestCase // @phpstan-ignore-next-line $names = TlsHelper::getCertificateNames($certificate); + self::assertIsArray($names); $this->assertSame('example.net', $names['cn']); $this->assertSame([ 'example.com',