From 86fedba365b5fc34be2311b36cda44656d58db66 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 10 Dec 2024 16:11:50 +0100 Subject: [PATCH] Fix 2.2 CI (#12228) --- phpstan/baseline.neon | 118 +++++++----------- src/Composer/Autoload/AutoloadGenerator.php | 2 +- .../Test/Package/RootAliasPackageTest.php | 2 +- .../Repository/FilesystemRepositoryTest.php | 1 + .../Test/Repository/Vcs/GitLabDriverTest.php | 6 +- 5 files changed, 50 insertions(+), 79 deletions(-) diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index c335349c5..c249aa7ac 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -30,11 +30,6 @@ parameters: count: 1 path: ../src/Composer/Autoload/AutoloadGenerator.php - - - message: "#^Only booleans are allowed in &&, array\\\\|int\\|string\\>\\|bool\\|string\\>\\|bool\\|string\\|null given on the left side\\.$#" - count: 1 - path: ../src/Composer/Autoload/AutoloadGenerator.php - - message: "#^Only booleans are allowed in &&, bool\\|null given on the left side\\.$#" count: 1 @@ -2480,11 +2475,6 @@ parameters: count: 1 path: ../src/Composer/Config.php - - - message: "#^Only booleans are allowed in an if condition, bool\\|string given\\.$#" - count: 1 - path: ../src/Composer/Config.php - - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" count: 1 @@ -2580,11 +2570,6 @@ parameters: count: 2 path: ../src/Composer/Console/Application.php - - - message: "#^Only booleans are allowed in an if condition, Composer\\\\Composer\\|null given\\.$#" - count: 1 - path: ../src/Composer/Console/Application.php - - message: "#^Only booleans are allowed in an if condition, array\\\\|null given\\.$#" count: 1 @@ -2725,11 +2710,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/MultiConflictRule.php - - - message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Pool.php - - message: "#^Cannot call method getPackages\\(\\) on Composer\\\\Repository\\\\LockArrayRepository\\|null\\.$#" count: 2 @@ -2755,11 +2735,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/PoolBuilder.php - - - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/PoolBuilder.php - - message: "#^Parameter \\#4 \\$index of method Composer\\\\DependencyResolver\\\\PoolBuilder\\:\\:removeLoadedPackage\\(\\) expects int, int\\|string given\\.$#" count: 1 @@ -2775,11 +2750,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/PoolOptimizer.php - - - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" - count: 4 - path: ../src/Composer/DependencyResolver/PoolOptimizer.php - - message: "#^Cannot call method getRepoName\\(\\) on Composer\\\\Repository\\\\RepositoryInterface\\|null\\.$#" count: 3 @@ -3970,11 +3940,26 @@ parameters: count: 1 path: ../src/Composer/InstalledVersions.php + - + message: "#^Method Composer\\\\InstalledVersions\\:\\:getInstalled\\(\\) should return array\\, dev\\: bool, install_path\\: string, type\\: string\\}, versions\\: array\\, reference\\?\\: string, replaced\\?\\: array\\, provided\\?\\: array\\, install_path\\?\\: string, \\.\\.\\.\\}\\>\\}\\> but returns array\\, dev\\: bool\\}, versions\\: array\\, dev_requirement\\: bool, replaced\\?\\: array\\, \\.\\.\\.\\}\\>\\}\\>\\.$#" + count: 1 + path: ../src/Composer/InstalledVersions.php + - message: "#^Parameter \\#1 \\$constraints of method Composer\\\\Semver\\\\VersionParser\\:\\:parseConstraints\\(\\) expects string, string\\|null given\\.$#" count: 1 path: ../src/Composer/InstalledVersions.php + - + message: "#^Static property Composer\\\\InstalledVersions\\:\\:\\$installed \\(array\\{\\}\\|array\\{root\\: array\\{name\\: string, version\\: string, reference\\: string, pretty_version\\: string, aliases\\: array\\, dev\\: bool, install_path\\: string, type\\: string\\}, versions\\: array\\, reference\\?\\: string, replaced\\?\\: array\\, provided\\?\\: array\\, install_path\\?\\: string, \\.\\.\\.\\}\\>\\}\\|null\\) does not accept array\\{root\\: array\\{name\\: string, pretty_version\\: string, version\\: string, reference\\: string\\|null, type\\: string, install_path\\: string, aliases\\: array\\, dev\\: bool\\}, versions\\: array\\, dev_requirement\\: bool, replaced\\?\\: array\\, \\.\\.\\.\\}\\>\\}\\.$#" + count: 2 + path: ../src/Composer/InstalledVersions.php + + - + message: "#^Static property Composer\\\\InstalledVersions\\:\\:\\$installedByVendor \\(array\\, dev\\: bool, install_path\\: string, type\\: string\\}, versions\\: array\\, reference\\?\\: string, replaced\\?\\: array\\, provided\\?\\: array\\, install_path\\?\\: string, \\.\\.\\.\\}\\>\\}\\>\\) does not accept non\\-empty\\-array\\, dev\\: bool, install_path\\: string, type\\: string\\}, versions\\: array\\, reference\\?\\: string\\|null, replaced\\?\\: array\\, provided\\?\\: array\\, install_path\\?\\: string, \\.\\.\\.\\}\\>\\}\\>\\.$#" + count: 1 + path: ../src/Composer/InstalledVersions.php + - message: "#^Cannot call method getPackages\\(\\) on Composer\\\\Repository\\\\LockArrayRepository\\|null\\.$#" count: 1 @@ -4135,11 +4120,6 @@ 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 @@ -4150,11 +4130,6 @@ 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 @@ -5042,7 +5017,7 @@ parameters: - message: "#^Only booleans are allowed in an if condition, Composer\\\\Repository\\\\InstalledRepositoryInterface\\|null given\\.$#" - count: 3 + count: 1 path: ../src/Composer/Plugin/PluginManager.php - @@ -5227,7 +5202,7 @@ parameters: - message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Repository/ComposerRepository.php - @@ -6465,21 +6440,11 @@ parameters: count: 2 path: ../src/Composer/Util/GitHub.php - - - message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" - count: 1 - path: ../src/Composer/Util/GitHub.php - - message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" count: 1 path: ../src/Composer/Util/GitHub.php - - - message: "#^Parameter \\#1 \\$str of function trim expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/GitHub.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 2 @@ -8354,8 +8319,28 @@ parameters: path: ../tests/Composer/Test/Package/LockerTest.php - - message: "#^Parameter \\#1 \\$aliasOf of class Composer\\\\Package\\\\RootAliasPackage constructor expects Composer\\\\Package\\\\RootPackage, object given\\.$#" - count: 5 + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:setConflicts\\(\\)\\.$#" + count: 1 + path: ../tests/Composer/Test/Package/RootAliasPackageTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:setDevRequires\\(\\)\\.$#" + count: 1 + path: ../tests/Composer/Test/Package/RootAliasPackageTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:setProvides\\(\\)\\.$#" + count: 1 + path: ../tests/Composer/Test/Package/RootAliasPackageTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:setReplaces\\(\\)\\.$#" + count: 1 + path: ../tests/Composer/Test/Package/RootAliasPackageTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:setRequires\\(\\)\\.$#" + count: 1 path: ../tests/Composer/Test/Package/RootAliasPackageTest.php - @@ -8578,36 +8563,21 @@ parameters: count: 1 path: ../tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\\\:\\:get\\(\\)\\.$#" + count: 3 + path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php + - message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#" count: 1 path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - - message: "#^Parameter \\#1 \\$io of static method Composer\\\\Repository\\\\Vcs\\\\GitLabDriver\\:\\:supports\\(\\) expects Composer\\\\IO\\\\IOInterface, object given\\.$#" - count: 1 - path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - - - message: "#^Parameter \\#2 \\$io of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\IO\\\\IOInterface, object given\\.$#" - count: 9 - path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - message: "#^Parameter \\#4 \\$body of class Composer\\\\Util\\\\Http\\\\Response constructor expects string\\|null, string\\|false given\\.$#" count: 2 path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - - message: "#^Parameter \\#4 \\$httpDownloader of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\Util\\\\HttpDownloader, object given\\.$#" - count: 9 - path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - - - message: "#^Parameter \\#5 \\$process of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\Util\\\\ProcessExecutor, object given\\.$#" - count: 9 - path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php - - message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#" count: 1 diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 94f6ac971..7d3bb0466 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1193,7 +1193,7 @@ HEADER; } foreach ((array) $loader as $prop => $value) { - if (is_array($value) && $value && 0 === strpos($prop, $prefix)) { + if (is_array($value) && \count($value) !== 0 && 0 === strpos($prop, $prefix)) { $maps[substr($prop, $prefixLen)] = $value; } } diff --git a/tests/Composer/Test/Package/RootAliasPackageTest.php b/tests/Composer/Test/Package/RootAliasPackageTest.php index 10f9a179c..7ae1b373c 100644 --- a/tests/Composer/Test/Package/RootAliasPackageTest.php +++ b/tests/Composer/Test/Package/RootAliasPackageTest.php @@ -81,7 +81,7 @@ class RootAliasPackageTest extends TestCase } /** - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ObjectProphecy<\Composer\Package\RootPackage> */ protected function getMockRootPackageInterface() { diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index 82cdff69a..49ee85ef9 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -206,6 +206,7 @@ class FilesystemRepositoryTest extends TestCase self::assertTrue($result, 'The file should be considered valid'); $rawData = \Composer\InstalledVersions::getAllRawData(); $rawData = end($rawData); + /** @phpstan-ignore-next-line */ self::assertSame(array( 'root' => array( 'install_path' => __DIR__ . '/Fixtures/./', diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index fd6f2936d..25c3f4841 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -33,15 +33,15 @@ class GitLabDriverTest extends TestCase */ private $config; /** - * @var \Prophecy\Prophecy\ObjectProphecy + * @var \Prophecy\Prophecy\ObjectProphecy<\Composer\IO\IOInterface> */ private $io; /** - * @var \Prophecy\Prophecy\ObjectProphecy + * @var \Prophecy\Prophecy\ObjectProphecy<\Composer\Util\ProcessExecutor> */ private $process; /** - * @var \Prophecy\Prophecy\ObjectProphecy + * @var \Prophecy\Prophecy\ObjectProphecy<\Composer\Util\HttpDownloader> */ private $httpDownloader;