1
0
Fork 0

Add --strict-ambiguous to dump-autoload command (#12119)

Fixes #6221
pull/12129/head
Jordi Boggiano 2024-09-19 11:40:57 +02:00 committed by GitHub
parent 3e7b3b26df
commit a03331bd21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -990,6 +990,8 @@ performance.
Multiple requirements can be ignored via wildcard. Multiple requirements can be ignored via wildcard.
* **--strict-psr:** Return a failed exit code (1) if PSR-4 or PSR-0 mapping errors * **--strict-psr:** Return a failed exit code (1) if PSR-4 or PSR-0 mapping errors
are present. Requires --optimize to work. are present. Requires --optimize to work.
* **--strict-ambiguous:** Return a failed exit code (2) if the same class is found
in multiple files. Requires --optimize to work.
## clear-cache / clearcache / cc ## clear-cache / clearcache / cc

View File

@ -43,6 +43,7 @@ class DumpAutoloadCommand extends BaseCommand
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'), new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
new InputOption('strict-psr', null, InputOption::VALUE_NONE, 'Return a failed status code (1) if PSR-4 or PSR-0 mapping errors are present. Requires --optimize to work.'), new InputOption('strict-psr', null, InputOption::VALUE_NONE, 'Return a failed status code (1) if PSR-4 or PSR-0 mapping errors are present. Requires --optimize to work.'),
new InputOption('strict-ambiguous', null, InputOption::VALUE_NONE, 'Return a failed status code (2) if the same class is found in multiple files. Requires --optimize to work.'),
]) ])
->setHelp( ->setHelp(
<<<EOT <<<EOT
@ -74,6 +75,9 @@ EOT
if ($input->getOption('strict-psr') && !$optimize && !$authoritative) { if ($input->getOption('strict-psr') && !$optimize && !$authoritative) {
throw new \InvalidArgumentException('--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.'); throw new \InvalidArgumentException('--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.');
} }
if ($input->getOption('strict-ambiguous') && !$optimize && !$authoritative) {
throw new \InvalidArgumentException('--strict-ambiguous mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.');
}
if ($authoritative) { if ($authoritative) {
$this->getIO()->write('<info>Generating optimized autoload files (authoritative)</info>'); $this->getIO()->write('<info>Generating optimized autoload files (authoritative)</info>');
@ -124,6 +128,10 @@ EOT
return 1; return 1;
} }
if ($input->getOption('strict-ambiguous') && count($classMap->getAmbiguousClasses()) > 0) {
return 2;
}
return 0; return 0;
} }
} }