Revert autoload script, since they will not run on dependency

This commit is contained in:
Tomas Votruba 2018-12-26 01:26:19 +01:00
parent a758695d43
commit c9c29741b6
4 changed files with 44 additions and 150 deletions

View File

@ -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"

View File

@ -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'

View File

@ -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'

View File

@ -1,137 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\Composer;
use Composer\Script\Event;
use Nette\Utils\Strings;
final class MonorepoAutoloadEventSubscriber
{
/**
* @see https://www.drupal.org/files/issues/vendor-classmap-2468499-14.patch
*/
public static function preAutoloadDump(Event $event): void
{
// input
$packagesDirectory = 'packages';
$mainNamespace = 'Rector';
$absolutePackagesDirectory = getcwd() . '/' . $packagesDirectory . '/*';
$package = $event->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 . '/(?<namespacePart>.*?)/#');
if (! isset($match['namespacePart'])) {
continue;
}
$namespace = $mainNamespace . '\\' . $match['namespacePart'] . '\\';
if ($namespaceSuffix) {
$namespace .= $namespaceSuffix . '\\';
}
$namespaceToDirectory[$namespace] = $directory;
}
return $namespaceToDirectory;
}
}