From 33ffd5abc319053d174565b85261388124685676 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 4 Oct 2024 11:13:17 +0200 Subject: [PATCH] Fix --strict-ambiguous to really report all issues, fixes #12140 (#12148) --- composer.json | 2 +- composer.lock | 18 +++++++++--------- src/Composer/Autoload/AutoloadGenerator.php | 9 +++++++-- src/Composer/Command/DumpAutoloadCommand.php | 5 +++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 060b41d9d..a943cd7f9 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require": { "php": "^7.2.5 || ^8.0", "composer/ca-bundle": "^1.5", - "composer/class-map-generator": "^1.3.3", + "composer/class-map-generator": "^1.4.0", "composer/metadata-minifier": "^1.0", "composer/semver": "^3.3", "composer/spdx-licenses": "^1.5.7", diff --git a/composer.lock b/composer.lock index aa106a018..770ebda51 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d6685068b4f2660ec25263c8ecf9a367", + "content-hash": "7c2f8d4d04b8146b2fcd203cb81fa8d5", "packages": [ { "name": "composer/ca-bundle", @@ -84,16 +84,16 @@ }, { "name": "composer/class-map-generator", - "version": "1.3.4", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/composer/class-map-generator.git", - "reference": "b1b3fd0b4eaf3ddf3ee230bc340bf3fff454a1a3" + "reference": "98bbf6780e56e0fd2404fe4b82eb665a0f93b783" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/class-map-generator/zipball/b1b3fd0b4eaf3ddf3ee230bc340bf3fff454a1a3", - "reference": "b1b3fd0b4eaf3ddf3ee230bc340bf3fff454a1a3", + "url": "https://api.github.com/repos/composer/class-map-generator/zipball/98bbf6780e56e0fd2404fe4b82eb665a0f93b783", + "reference": "98bbf6780e56e0fd2404fe4b82eb665a0f93b783", "shasum": "" }, "require": { @@ -106,8 +106,8 @@ "phpstan/phpstan-deprecation-rules": "^1", "phpstan/phpstan-phpunit": "^1", "phpstan/phpstan-strict-rules": "^1.1", - "symfony/filesystem": "^5.4 || ^6", - "symfony/phpunit-bridge": "^5" + "phpunit/phpunit": "^8", + "symfony/filesystem": "^5.4 || ^6" }, "type": "library", "extra": { @@ -137,7 +137,7 @@ ], "support": { "issues": "https://github.com/composer/class-map-generator/issues", - "source": "https://github.com/composer/class-map-generator/tree/1.3.4" + "source": "https://github.com/composer/class-map-generator/tree/1.4.0" }, "funding": [ { @@ -153,7 +153,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:13:04+00:00" + "time": "2024-10-03T18:14:00+00:00" }, { "name": "composer/metadata-minifier", diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 2296a7eb1..86c9f184d 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -173,7 +173,7 @@ class AutoloadGenerator * @throws \Seld\JsonLint\ParsingException * @throws \RuntimeException */ - public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, string $targetDir, bool $scanPsrPackages = false, ?string $suffix = null, ?Locker $locker = null) + public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, string $targetDir, bool $scanPsrPackages = false, ?string $suffix = null, ?Locker $locker = null, bool $strictAmbiguous = false) { if ($this->classMapAuthoritative) { // Force scanPsrPackages when classmap is authoritative @@ -362,7 +362,12 @@ EOF; } $classMap = $classMapGenerator->getClassMap(); - foreach ($classMap->getAmbiguousClasses() as $className => $ambiguousPaths) { + if ($strictAmbiguous) { + $ambiguousClasses = $classMap->getAmbiguousClasses(false); + } else { + $ambiguousClasses = $classMap->getAmbiguousClasses(); + } + foreach ($ambiguousClasses as $className => $ambiguousPaths) { if (count($ambiguousPaths) > 1) { $this->io->writeError( 'Warning: Ambiguous class resolution, "'.$className.'"'. diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index 2e3181a27..cc0d7bf80 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -124,7 +124,8 @@ EOT 'composer', $optimize, null, - $composer->getLocker() + $composer->getLocker(), + $input->getOption('strict-ambiguous') ); $numberOfClasses = count($classMap); @@ -140,7 +141,7 @@ EOT return 1; } - if ($input->getOption('strict-ambiguous') && count($classMap->getAmbiguousClasses()) > 0) { + if ($input->getOption('strict-ambiguous') && count($classMap->getAmbiguousClasses(false)) > 0) { return 2; }