mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Add AutoloadWrongCasesEventSubscriber to simplify composer.json
This commit is contained in:
parent
85b1fed683
commit
82eedd4078
106
composer.json
106
composer.json
@ -93,107 +93,8 @@
|
||||
"packages/Twig/tests",
|
||||
"packages/Utils/tests",
|
||||
"tests/Source",
|
||||
"tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong",
|
||||
"tests/Issues/Issue594/Wrong",
|
||||
"tests/Rector/Assign/PropertyAssignToMethodCallRector/Wrong",
|
||||
"tests/Rector/RectorOrder/Wrong",
|
||||
"packages/DomainDrivenDesign/tests/Rector/ValueObjectRemoverRector/Wrong",
|
||||
"packages/DomainDrivenDesign/tests/Rector/ValueObjectRemoverDocBlockRector/Wrong",
|
||||
"tests/Rector/StaticCall/StaticCallToFunctionRector/Wrong",
|
||||
"tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/Wrong",
|
||||
"tests/Rector/MethodCall/StaticMethodNameReplacerRector/Wrong",
|
||||
"tests/Rector/MethodCall/MethodNameReplacerRector/Wrong",
|
||||
"tests/Rector/MethodBody/ReturnThisRemoveRector/Wrong",
|
||||
"tests/Rector/MethodBody/NormalToFluentRector/Wrong",
|
||||
"tests/Rector/MethodBody/FluentReplaceRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/UnsetAndIssetToMethodCallRector/Wrong",
|
||||
"tests/Rector/MagicDisclosure/ToStringToMethodCallRector/Wrong",
|
||||
"tests/Rector/Typehint/ReturnTypehintRector/Wrong",
|
||||
"tests/Rector/Typehint/ParentTypehintedArgumentRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentRemoverRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentAdderRector/Wrong",
|
||||
"tests/Rector/Argument/ArgumentDefaultValueReplacerRector/Wrong",
|
||||
"tests/Rector/Namespace_/NamespaceReplacerRector/Wrong",
|
||||
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Wrong",
|
||||
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source",
|
||||
"tests/Rector/Function_/FunctionToStaticCallRector/Wrong",
|
||||
"tests/Rector/Function_/FunctionReplaceRector/Wrong",
|
||||
"tests/Rector/Function_/FunctionToMethodCallRector/Wrong",
|
||||
"tests/Rector/Property/PropertyNameReplacerRector/Wrong",
|
||||
"tests/Rector/Property/PropertyToMethodRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/AnnotatedPropertyInjectToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DependencyInjection/ActionInjectionToConstructorInjectionRector/Wrong",
|
||||
"tests/Rector/Architecture/DoctrineRepositoryAsService/Wrong",
|
||||
"tests/Rector/Interface_/MergeInterfacesRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangeMethodVisibilityRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangePropertyVisibilityRector/Wrong",
|
||||
"tests/Rector/Visibility/ChangeConstantVisibilityRector/Wrong",
|
||||
"tests/Rector/Annotation/AnnotationReplacerRector/Wrong",
|
||||
"packages/CodeQuality/tests/Rector/Assign/CombinedAssignRector/Wrong",
|
||||
"packages/CodeQuality/tests/Rector/Ternary/UnnecessaryTernaryExpressionRector/Wrong",
|
||||
"packages/CodeQuality/tests/Rector/FuncCall/InArrayAndArrayKeysToArrayKeyExistsRector/Wrong",
|
||||
"tests/Rector/Constant/ClassConstantReplacerRector/Wrong",
|
||||
"tests/Rector/Constant/RenameClassConstantsUseToStringsRector/Wrong",
|
||||
"tests/Rector/Class_/ParentClassToTraitsRector/Wrong",
|
||||
"tests/Rector/Class_/ClassReplacerRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/DelegateExceptionArgumentsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/ArrayToYieldDataProviderRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/ExceptionAnnotationRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/TryCatchToExpectExceptionRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertPropertyExistsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertIssetToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertRegExpRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertComparisonToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertCompareToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertSameBoolNullToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertNotOperatorRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertInstanceOfComparisonRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/SpecificMethod/AssertFalseStrposToContainsRector/Wrong",
|
||||
"packages/PHPUnit/tests/Rector/GetMockRector/Wrong",
|
||||
"packages/Sylius/tests/Rector/Review/Wrong",
|
||||
"packages/Silverstripe/tests/Rector/DefineConstantToStaticCallRector/Wrong",
|
||||
"packages/Silverstripe/tests/Rector/ConstantToStaticCallRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/RedirectToRouteRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/AddFlashRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Controller/ActionSuffixRemoverRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Validator/ConstraintUrlOptionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Console/ConsoleExceptionToErrorEventConstantRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/SessionStrictTrueByDefaultYamlRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/SpaceBetweenKeyAndValueYamlRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Yaml/ParseFileRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/DependencyInjection/ContainerBuilderCompileEnvArgumentRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/VarDumper/VarDumperTestTraitMethodArgsRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/GetParameterToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/GetToConstructorInjectionRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/OptionNameRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/FormIsValidRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/StringFormTypeToClassRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Form/FormTypeGetParentRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Process/ProcessBuilderGetProcessRector/Wrong",
|
||||
"packages/Symfony/tests/Rector/Process/ProcessBuilderInstanceRector/Wrong",
|
||||
"packages/Twig/tests/Rector/SimpleFunctionAndFilterRector/Wrong",
|
||||
"packages/Jms/tests/Rector/Property/JmsInjectAnnotationRector/Wrong",
|
||||
"packages/Doctrine/tests/Rector/AliasToClassRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/RemoveNodeRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/IdentifierRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/ParamAndStaticVarNameRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/UseWithAliasRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/CatchAndClosureUseNameRector/Wrong",
|
||||
"packages/PhpParser/tests/Rector/SetLineRector/Wrong",
|
||||
"packages/CakePHP/tests/Rector/MethodCall/ModalToGetSetRector/Wrong",
|
||||
"packages/Sensio/tests/Rector/FrameworkExtraBundle/TemplateAnnotationRector/Wrong",
|
||||
"packages/Php/tests/Rector/Property/TypedPropertyRector/Wrong",
|
||||
"packages/Php/tests/Rector/FunctionLike/ExceptionHandlerTypehintRector/Wrong",
|
||||
"packages/Php/tests/Rector/FunctionLike/Php4ConstructorRector/Wrong",
|
||||
"packages/Php/tests/Rector/Assign/AssignArrayToStringRector/Wrong",
|
||||
"packages/Php/tests/Rector/FuncCall/CountOnNullRector/Wrong",
|
||||
"tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Source"
|
||||
"tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Source",
|
||||
"tests/Rector/Namespace_/PseudoNamespaceToNamespaceRector/Source"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
@ -217,6 +118,9 @@
|
||||
"rector-prefixed": [
|
||||
"bin/rector-prefixed/build-prefixed-rector.sh",
|
||||
"bin/rector-prefixed/publish-to-github.sh"
|
||||
],
|
||||
"pre-autoload-dump": [
|
||||
"Rector\\Tests\\Composer\\AutoloadWrongCasesEventSubscriber::preAutoloadDump"
|
||||
]
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
|
@ -2,7 +2,63 @@
|
||||
|
||||
namespace Rector\Tests\Composer;
|
||||
|
||||
use Composer\Script\Event;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
final class AutoloadWrongCasesEventSubscriber
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private static $wrongDirectories = [];
|
||||
|
||||
}
|
||||
/**
|
||||
* @see https://www.drupal.org/files/issues/vendor-classmap-2468499-14.patch
|
||||
*/
|
||||
public static function preAutoloadDump(Event $event)
|
||||
{
|
||||
$paths = [
|
||||
__DIR__ . '/../../tests/Rector/*',
|
||||
__DIR__ . '/../../tests/Issues/*',
|
||||
__DIR__ . '/../../packages/*'
|
||||
];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
self::$wrongDirectories = array_merge(self::$wrongDirectories, self::getWrongDirectoriesInPath($path));
|
||||
}
|
||||
|
||||
$package = $event->getComposer()->getPackage();
|
||||
$autoload = $package->getDevAutoload();
|
||||
$autoload['classmap'] = array_merge($autoload['classmap'] ?? [], self::$wrongDirectories);
|
||||
$package->setDevAutoload($autoload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private static function getWrongDirectoriesInPath(string $path): array
|
||||
{
|
||||
$globResult = self::glob_recursive($path, GLOB_ONLYDIR);
|
||||
|
||||
return array_filter($globResult, function ($name) {
|
||||
return strpos($name, '/Wrong');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://stackoverflow.com/a/12109100/1348344
|
||||
*/
|
||||
private static function glob_recursive(string $pattern, $flags = 0)
|
||||
{
|
||||
$files = glob($pattern, $flags);
|
||||
|
||||
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
|
||||
$files = array_merge($files, self::glob_recursive($dir.'/'.basename($pattern), $flags));
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user