1
0
Fork 0

Fixed PSR violations for classes not matching the namespace of a rule being hidden, fixes #11957

pull/12007/head
Jordi Boggiano 2024-05-31 15:08:44 +02:00
parent c1be804a0c
commit dc857b4f91
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
4 changed files with 49 additions and 33 deletions

View File

@ -24,7 +24,7 @@
"require": { "require": {
"php": "^7.2.5 || ^8.0", "php": "^7.2.5 || ^8.0",
"composer/ca-bundle": "^1.0", "composer/ca-bundle": "^1.0",
"composer/class-map-generator": "^1.0", "composer/class-map-generator": "^1.3.1",
"composer/metadata-minifier": "^1.0", "composer/metadata-minifier": "^1.0",
"composer/semver": "^3.3", "composer/semver": "^3.3",
"composer/spdx-licenses": "^1.5.7", "composer/spdx-licenses": "^1.5.7",
@ -81,7 +81,13 @@
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Composer\\Test\\": "tests/Composer/Test/" "Composer\\Test\\": "tests/Composer/Test/"
} },
"exclude-from-classmap": [
"tests/Composer/Test/Fixtures/",
"tests/Composer/Test/Autoload/Fixtures",
"tests/Composer/Test/Autoload/MinimumVersionSupport",
"tests/Composer/Test/Plugin/Fixtures"
]
}, },
"bin": [ "bin": [
"bin/composer" "bin/composer"

48
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9cc98d4fd8dcc30565a6570841b7ec85", "content-hash": "1322de6eee2357fec92034b7b41e6512",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
@ -84,16 +84,16 @@
}, },
{ {
"name": "composer/class-map-generator", "name": "composer/class-map-generator",
"version": "1.1.1", "version": "1.3.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/class-map-generator.git", "url": "https://github.com/composer/class-map-generator.git",
"reference": "8286a62d243312ed99b3eee20d5005c961adb311" "reference": "5bb7f1e135ccc696bdccb7ec945403fcaac144d5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/class-map-generator/zipball/8286a62d243312ed99b3eee20d5005c961adb311", "url": "https://api.github.com/repos/composer/class-map-generator/zipball/5bb7f1e135ccc696bdccb7ec945403fcaac144d5",
"reference": "8286a62d243312ed99b3eee20d5005c961adb311", "reference": "5bb7f1e135ccc696bdccb7ec945403fcaac144d5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -137,7 +137,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/composer/class-map-generator/issues", "issues": "https://github.com/composer/class-map-generator/issues",
"source": "https://github.com/composer/class-map-generator/tree/1.1.1" "source": "https://github.com/composer/class-map-generator/tree/1.3.1"
}, },
"funding": [ "funding": [
{ {
@ -153,7 +153,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-03-15T12:53:41+00:00" "time": "2024-05-31T15:31:05+00:00"
}, },
{ {
"name": "composer/metadata-minifier", "name": "composer/metadata-minifier",
@ -2015,16 +2015,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.11.2", "version": "1.11.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "0d5d4294a70deb7547db655c47685d680e39cfec" "reference": "e64220a05c1209fc856d58e789c3b7a32c0bb9a5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d5d4294a70deb7547db655c47685d680e39cfec", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e64220a05c1209fc856d58e789c3b7a32c0bb9a5",
"reference": "0d5d4294a70deb7547db655c47685d680e39cfec", "reference": "e64220a05c1209fc856d58e789c3b7a32c0bb9a5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2069,7 +2069,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-05-24T13:23:04+00:00" "time": "2024-05-31T13:53:37+00:00"
}, },
{ {
"name": "phpstan/phpstan-deprecation-rules", "name": "phpstan/phpstan-deprecation-rules",
@ -2221,16 +2221,16 @@
}, },
{ {
"name": "phpstan/phpstan-symfony", "name": "phpstan/phpstan-symfony",
"version": "1.4.1", "version": "1.4.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan-symfony.git", "url": "https://github.com/phpstan/phpstan-symfony.git",
"reference": "d530cfebba55763732bc2421f79d2576d9d7942f" "reference": "af6ae0f4b91bc080265e80776af26da3e5befb28"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/d530cfebba55763732bc2421f79d2576d9d7942f", "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/af6ae0f4b91bc080265e80776af26da3e5befb28",
"reference": "d530cfebba55763732bc2421f79d2576d9d7942f", "reference": "af6ae0f4b91bc080265e80776af26da3e5befb28",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2287,22 +2287,22 @@
"description": "Symfony Framework extensions and rules for PHPStan", "description": "Symfony Framework extensions and rules for PHPStan",
"support": { "support": {
"issues": "https://github.com/phpstan/phpstan-symfony/issues", "issues": "https://github.com/phpstan/phpstan-symfony/issues",
"source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.1" "source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.3"
}, },
"time": "2024-05-24T14:00:29+00:00" "time": "2024-05-30T15:01:27+00:00"
}, },
{ {
"name": "symfony/phpunit-bridge", "name": "symfony/phpunit-bridge",
"version": "v7.0.7", "version": "v7.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/phpunit-bridge.git", "url": "https://github.com/symfony/phpunit-bridge.git",
"reference": "0a0b90ba08b9a03e09ad49f8d613bdf3eca3a7a9" "reference": "1168ef27edb094fe4ba755ec937cf62a6dff84eb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/0a0b90ba08b9a03e09ad49f8d613bdf3eca3a7a9", "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/1168ef27edb094fe4ba755ec937cf62a6dff84eb",
"reference": "0a0b90ba08b9a03e09ad49f8d613bdf3eca3a7a9", "reference": "1168ef27edb094fe4ba755ec937cf62a6dff84eb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2354,7 +2354,7 @@
"description": "Provides utilities for PHPUnit, especially user deprecation notices management", "description": "Provides utilities for PHPUnit, especially user deprecation notices management",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/phpunit-bridge/tree/v7.0.7" "source": "https://github.com/symfony/phpunit-bridge/tree/v7.1.0"
}, },
"funding": [ "funding": [
{ {
@ -2370,7 +2370,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-04-18T09:29:19+00:00" "time": "2024-05-17T10:55:18+00:00"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -319,7 +319,7 @@ EOF;
EOF; EOF;
} }
$excluded = null; $excluded = [];
if (!empty($autoloads['exclude-from-classmap'])) { if (!empty($autoloads['exclude-from-classmap'])) {
$excluded = $autoloads['exclude-from-classmap']; $excluded = $autoloads['exclude-from-classmap'];
} }
@ -348,7 +348,14 @@ EOF;
continue; continue;
} }
$classMapGenerator->scanPaths($dir, $this->buildExclusionRegex($dir, $excluded), $group['type'], $namespace); // if the vendor dir is contained within a psr-0/psr-4 dir being scanned we exclude it
if (str_contains($vendorPath, $dir.'/')) {
$exclusionRegex = $this->buildExclusionRegex($dir, array_merge($excluded, [$vendorPath.'/']));
} else {
$exclusionRegex = $this->buildExclusionRegex($dir, $excluded);
}
$classMapGenerator->scanPaths($dir, $exclusionRegex, $group['type'], $namespace);
} }
} }
} }
@ -368,6 +375,9 @@ EOF;
); );
} }
} }
// output PSR violations which are not coming from the vendor dir
$classMap->clearPsrViolationsByPath($vendorPath);
foreach ($classMap->getPsrViolations() as $msg) { foreach ($classMap->getPsrViolations() as $msg) {
$this->io->writeError("<warning>$msg</warning>"); $this->io->writeError("<warning>$msg</warning>");
} }
@ -460,12 +470,12 @@ EOF;
} }
/** /**
* @param array<string>|null $excluded * @param array<string> $excluded
* @return non-empty-string|null * @return non-empty-string|null
*/ */
private function buildExclusionRegex(string $dir, ?array $excluded): ?string private function buildExclusionRegex(string $dir, array $excluded): ?string
{ {
if (null === $excluded) { if ([] === $excluded) {
return null; return null;
} }
@ -602,7 +612,7 @@ EOF;
} }
if (isset($autoloads['classmap'])) { if (isset($autoloads['classmap'])) {
$excluded = null; $excluded = [];
if (!empty($autoloads['exclude-from-classmap'])) { if (!empty($autoloads['exclude-from-classmap'])) {
$excluded = $autoloads['exclude-from-classmap']; $excluded = $autoloads['exclude-from-classmap'];
} }

View File

@ -62,7 +62,7 @@ class DumpAutoloadCommandTest extends TestCase
self::assertSame(1, $appTester->run(['command' => 'dump-autoload', '--optimize' => true, '--strict-psr' => true])); self::assertSame(1, $appTester->run(['command' => 'dump-autoload', '--optimize' => true, '--strict-psr' => true]));
$output = $appTester->getDisplay(true); $output = $appTester->getDisplay(true);
self::assertMatchesRegularExpression('/Class Application\\\Src\\\Foo located in .*? does not comply with psr-4 autoloading standard. Skipping./', $output); self::assertMatchesRegularExpression('#Class Application\\\\Src\\\\Foo located in .*? does not comply with psr-4 autoloading standard \(rule: Application\\\\ => \./src\)\. Skipping\.#', $output);
} }
public function testUsingClassmapAuthoritative(): void public function testUsingClassmapAuthoritative(): void