diff --git a/composer.json b/composer.json index 94a9d58c1f7..299f90153b6 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,52 @@ }, "autoload": { "psr-4": { - "Rector\\": "src" + "Rector\\": "src", + "Rector\\ContributorTools\\": "packages/ContributorTools/src", + "Rector\\ConsoleDiffer\\": "packages/ConsoleDiffer/src", + "Rector\\CodingStyle\\": "packages/CodingStyle/src", + "Rector\\DeadCode\\": "packages/DeadCode/src", + "Rector\\Guzzle\\": "packages/Guzzle/src", + "Rector\\CodeQuality\\": "packages/CodeQuality/src", + "Rector\\DomainDrivenDesign\\": "packages/DomainDrivenDesign/src", + "Rector\\NodeTypeResolver\\": "packages/NodeTypeResolver/src", + "Rector\\Symfony\\": "packages/Symfony/src", + "Rector\\CakePHP\\": "packages/CakePHP/src", + "Rector\\Php\\": "packages/Php/src", + "Rector\\Jms\\": "packages/Jms/src", + "Rector\\Silverstripe\\": "packages/Silverstripe/src", + "Rector\\Sensio\\": "packages/Sensio/src", + "Rector\\Sylius\\": "packages/Sylius/src", + "Rector\\PHPStan\\": "packages/PHPStan/src", + "Rector\\PHPUnit\\": "packages/PHPUnit/src", + "Rector\\Twig\\": "packages/Twig/src", + "Rector\\PhpParser\\": "packages/PhpParser/src", + "Rector\\Doctrine\\": "packages/Doctrine/src", + "Rector\\FileSystemRector\\": "packages/FileSystemRector/src" } }, "autoload-dev": { "psr-4": { - "Rector\\Tests\\": "tests" + "Rector\\Tests\\": "tests", + "Rector\\NodeTypeResolver\\Tests\\": "packages/NodeTypeResolver/tests", + "Rector\\CakePHP\\Tests\\": "packages/CakePHP/tests", + "Rector\\CodeQuality\\Tests\\": "packages/CodeQuality/tests", + "Rector\\DeadCode\\Tests\\": "packages/DeadCode/tests", + "Rector\\CodingStyle\\Tests\\": "packages/CodingStyle/tests", + "Rector\\DomainDrivenDesign\\Tests\\": "packages/DomainDrivenDesign/tests", + "Rector\\Guzzle\\Tests\\": "packages/Guzzle/tests", + "Rector\\Php\\Tests\\": "packages/Php/tests", + "Rector\\Jms\\Tests\\": "packages/Jms/tests", + "Rector\\Symfony\\Tests\\": "packages/Symfony/tests", + "Rector\\Silverstripe\\Tests\\": "packages/Silverstripe/tests", + "Rector\\Sensio\\Tests\\": "packages/Sensio/tests", + "Rector\\Sylius\\Tests\\": "packages/Sylius/tests", + "Rector\\PHPStan\\Tests\\": "packages/PHPStan/tests", + "Rector\\PHPUnit\\Tests\\": "packages/PHPUnit/tests", + "Rector\\PhpParser\\Tests\\": "packages/PhpParser/tests", + "Rector\\Twig\\Tests\\": "packages/Twig/tests", + "Rector\\Doctrine\\Tests\\": "packages/Doctrine/tests", + "Rector\\FileSystemRector\\Tests\\": "packages/FileSystemRector/tests" }, "classmap": [ "examples", @@ -54,20 +94,14 @@ "symplify/easy-coding-standard": "Required to enable '--with-style' option. Use in case you don't have PHP_CodeSniffer or PHP-CS-Fixer yet." }, "scripts": { - "complete-check": [ - "@check-cs", - "phpunit", - "@phpstan", - "@update-docs" - ], + "complete-check": ["@check-cs", "phpunit", "@phpstan", "@update-docs"], "check-cs": "vendor/bin/ecs check bin packages src tests", "fix-cs": [ "vendor/bin/ecs check bin packages src tests --fix", "bin/clean_trailing_spaces.sh" ], "phpstan": "vendor/bin/phpstan analyse packages src tests", - "docs": "bin/rector generate-docs > docs/AllRectorsOverview.md", - "pre-autoload-dump": "Rector\\Composer\\MonorepoAutoloadEventSubscriber::preAutoloadDump" + "docs": "bin/rector generate-docs > docs/AllRectorsOverview.md" }, "scripts-descriptions": { "update-docs": "Regenerate descriptions of all Rectors to docs/AllRectorsOverview.md file" diff --git a/ecs.yml b/ecs.yml index 68058da59a7..776ed46867b 100644 --- a/ecs.yml +++ b/ecs.yml @@ -81,7 +81,6 @@ parameters: Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff: # required by Composer interface - - 'src/Composer/*.php' - 'src/Php/TypeAnalyzer.php' # exclusive static config for type support - 'src/Php/PhpTypeSupport.php' diff --git a/phpstan.neon b/phpstan.neon index c2a0b4a2591..c75db23df11 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,8 +9,6 @@ parameters: level: 7 excludes_analyse: - # static file missing autoload - - 'src/Composer/MonorepoAutoloadEventSubscriber.php' # test files - '*packages/NodeTypeResolver/tests/Source/AnotherClass.php' - '*tests/Rector/MethodCall/MethodNameReplacerRector/**/SomeClass.php' diff --git a/src/Composer/MonorepoAutoloadEventSubscriber.php b/src/Composer/MonorepoAutoloadEventSubscriber.php deleted file mode 100644 index 5efd5972a0b..00000000000 --- a/src/Composer/MonorepoAutoloadEventSubscriber.php +++ /dev/null @@ -1,137 +0,0 @@ -getComposer()->getPackage(); - - // src - $srcDirectories = self::getDirectoriesInPath($absolutePackagesDirectory, 'src'); - $namespaceToDirectory = self::createNamespaceToDirectory($srcDirectories, $mainNamespace, $packagesDirectory); - - $autoload = $package->getAutoload(); - $autoload['psr-4'] = array_merge($autoload['psr-4'], $namespaceToDirectory); - $package->setAutoload($autoload); - - // tests - $testDirectories = self::getDirectoriesInPath($absolutePackagesDirectory, 'tests'); - $namespaceToDirectory = self::createNamespaceToDirectory( - $testDirectories, - $mainNamespace, - $packagesDirectory, - 'Tests' - ); - - $devAutoload = $package->getDevAutoload(); - $devAutoload['psr-4'] = array_merge($devAutoload['psr-4'], $namespaceToDirectory); - $package->setDevAutoload($devAutoload); - } - - /** - * @return string[] - */ - private static function getDirectoriesInPath(string $directory, string $name): array - { - $globResult = self::globRecursive($directory, GLOB_ONLYDIR); - - $directories = array_filter($globResult, function ($path) use ($name) { - // keep only dirs ending with "$name" - return Strings::match($path, '#\/' . preg_quote($name) . '$#') && ! Strings::contains($path, 'templates'); - }); - - $directories = self::absolutizePaths($directories); - - return self::relativizeToCwd($directories); - } - - /** - * @see https://stackoverflow.com/a/12109100/1348344 - * @return string[] - */ - private static function globRecursive(string $pattern, int $flags = 0): array - { - $files = glob($pattern, $flags); - foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { - $files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern), $flags)); - } - return $files; - } - - /** - * @param string[] $directories - * @return string[] - */ - private static function relativizeToCwd(array $directories): array - { - foreach ($directories as $key => $directory) { - $directories[$key] = Strings::substring($directory, strlen(getcwd()) + 1); - } - - return $directories; - } - - /** - * @param string[] $paths - * @return string[] - */ - private static function absolutizePaths(array $paths): array - { - foreach ($paths as $key => $path) { - $realpath = realpath($path); - if ($realpath) { - $paths[$key] = $realpath; - } - } - - return $paths; - } - - /** - * From: - * "packages/SomePath/src" - * - * to: - * "Rector\SomePath\" => "packages/SomePath/src" - * - * @param string[] $directories - * @return string[] - */ - private static function createNamespaceToDirectory( - array $directories, - string $mainNamespace, - string $packagesDirectory, - string $namespaceSuffix = '' - ): array { - $namespaceToDirectory = []; - - foreach ($directories as $directory) { - $match = Strings::match($directory, '#' . $packagesDirectory . '/(?.*?)/#'); - if (! isset($match['namespacePart'])) { - continue; - } - - $namespace = $mainNamespace . '\\' . $match['namespacePart'] . '\\'; - if ($namespaceSuffix) { - $namespace .= $namespaceSuffix . '\\'; - } - $namespaceToDirectory[$namespace] = $directory; - } - - return $namespaceToDirectory; - } -}