Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .tools/visual-tests/screenshots/index--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/structure_article_edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/structure_category_edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/structure_category_edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/structure_slice_edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/structure_slice_edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 38 additions & 2 deletions src/ClassDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use function implode;
use function is_array;
use function is_dir;
use function json_decode;
use function realpath;
use function sort;
use function str_replace;
Expand Down Expand Up @@ -254,14 +255,18 @@ private function getRelevantPaths(): array

$paths = [];

// PSR-4 directories of the root composer package (project-level code)
// PSR-4 directories of the root composer package (project-level code), excluding vendor and the
// root's autoload-dev dirs (tests, dev tooling such as rector rules). Dev-only code never carries
// runtime attributes — and reflecting it needlessly autoloads dev-only vendor code (e.g. touching a
// custom rector rule pulls in rector's scoped vendor).
$rootPath = realpath(InstalledVersions::getRootPackage()['install_path']);
if (false !== $rootPath) {
$vendorPrefix = $rootPath . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR;
$devDirs = $this->getRootAutoloadDevDirs($rootPath);
foreach ($this->classLoader->getPrefixesPsr4() as $dirs) {
foreach ($dirs as $dir) {
$realDir = (string) realpath($dir);
if ('' !== $realDir && !str_starts_with($realDir, $vendorPrefix)) {
if ('' !== $realDir && !str_starts_with($realDir, $vendorPrefix) && !isset($devDirs[$realDir])) {
$paths[] = $realDir . DIRECTORY_SEPARATOR;
}
}
Expand All @@ -279,6 +284,37 @@ private function getRelevantPaths(): array
return $this->relevantPaths = $paths;
}

/**
* Returns the realpaths of the root package's autoload-dev PSR-4 directories, keyed for set lookup.
*
* These hold dev-only code (tests, dev tooling) that must be excluded from discovery: it is never
* registered at runtime, and a `--no-dev` install would not even autoload it.
*
* @return array<string, true>
*/
private function getRootAutoloadDevDirs(string $rootPath): array
{
$json = File::get($rootPath . DIRECTORY_SEPARATOR . 'composer.json');
if (null === $json) {
return [];
}

/** @var array{autoload-dev?: array{psr-4?: array<string, string|list<string>>}} $data */
$data = json_decode($json, true);

$dirs = [];
foreach ($data['autoload-dev']['psr-4'] ?? [] as $value) {
foreach ((array) $value as $dir) {
$realDir = realpath($rootPath . DIRECTORY_SEPARATOR . $dir);
if (false !== $realDir) {
$dirs[$realDir] = true;
}
}
}

return $dirs;
}

/** @return list<string> */
private function scanDirectory(string $dir, string $namespace): array
{
Expand Down