diff --git a/config/config.php b/config/config.php index 66262a22c57..222b9141f3b 100644 --- a/config/config.php +++ b/config/config.php @@ -2,17 +2,59 @@ declare(strict_types=1); +use Composer\Semver\VersionParser; +use Doctrine\Inflector\Inflector; +use Doctrine\Inflector\Rules\English\InflectorFactory; +use Ergebnis\Json\Printer\Printer; +use Ergebnis\Json\Printer\PrinterInterface; +use Idiosyncratic\EditorConfig\EditorConfig; use OndraM\CiDetector\CiDetector; +use PhpParser\BuilderFactory; +use PhpParser\Lexer; +use PhpParser\NodeFinder; +use PhpParser\NodeVisitor\CloningVisitor; +use PhpParser\NodeVisitor\NodeConnectingVisitor; +use PHPStan\Analyser\NodeScopeResolver; +use PHPStan\Analyser\ScopeFactory; +use PHPStan\Dependency\DependencyResolver; +use PHPStan\File\FileHelper; +use PHPStan\Parser\Parser; +use PHPStan\PhpDoc\TypeNodeResolver; +use PHPStan\PhpDocParser\Parser\PhpDocParser; +use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\Reflection\ReflectionProvider; +use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser; +use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser; +use Rector\Caching\Cache; +use Rector\Caching\CacheFactory; use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; use Rector\Config\RectorConfig; use Rector\Core\Bootstrap\ExtensionConfigResolver; +use Rector\Core\Console\ConsoleApplication; +use Rector\Core\Console\Style\RectorConsoleOutputStyle; +use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory; +use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector; +use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory; +use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator; +use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider; +use Rector\PSR4\Composer\PSR4NamespaceMatcher; +use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface; +use Symfony\Component\Console\Application; +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; +use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser; use Symplify\EasyParallel\ValueObject\EasyParallelConfig; +use Symplify\PackageBuilder\Parameter\ParameterProvider; +use Symplify\PackageBuilder\Php\TypeChecker; +use Symplify\PackageBuilder\Reflection\PrivatesAccessor; +use Symplify\PackageBuilder\Reflection\PrivatesCaller; use Symplify\PackageBuilder\Yaml\ParametersMerger; +use Symplify\SmartFileSystem\FileSystemFilter; +use Symplify\SmartFileSystem\FileSystemGuard; +use Symplify\SmartFileSystem\Finder\FinderSanitizer; +use Symplify\SmartFileSystem\Json\JsonFileSystem; +use Symplify\SmartFileSystem\SmartFileSystem; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->import(__DIR__ . '/services.php'); - $rectorConfig->import(__DIR__ . '/services-rules.php'); - // make use of https://github.com/symplify/easy-parallel $rectorConfig->import(EasyParallelConfig::FILE_PATH); @@ -52,6 +94,19 @@ return static function (RectorConfig $rectorConfig): void { __DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php', ]); + // psr-4 + $services->alias(PSR4AutoloadNamespaceMatcherInterface::class, PSR4NamespaceMatcher::class); + + $services->load('Rector\\', __DIR__ . '/../rules') + ->exclude([ + __DIR__ . '/../rules/*/ValueObject/*', + __DIR__ . '/../rules/*/Rector/*', + __DIR__ . '/../rules/*/Contract/*', + __DIR__ . '/../rules/*/Exception/*', + __DIR__ . '/../rules/*/Enum/*', + __DIR__ . '/../rules/DowngradePhp80/Reflection/SimplePhpParameterReflection.php', + ]); + // parallel $services->set(ParametersMerger::class); @@ -70,4 +125,101 @@ return static function (RectorConfig $rectorConfig): void { // require only in dev $rectorConfig->import(__DIR__ . '/../utils/compiler/config/config.php', null, 'not_found'); + + $services->load('Rector\Core\\', __DIR__ . '/../src') + ->exclude([ + __DIR__ . '/../src/Rector', + __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', + __DIR__ . '/../src/Exception', + __DIR__ . '/../src/DependencyInjection/CompilerPass', + __DIR__ . '/../src/DependencyInjection/Loader', + __DIR__ . '/../src/Kernel', + __DIR__ . '/../src/ValueObject', + __DIR__ . '/../src/Bootstrap', + __DIR__ . '/../src/Enum', + __DIR__ . '/../src/PhpParser/Node/CustomNode', + __DIR__ . '/../src/PhpParser/ValueObject', + __DIR__ . '/../src/functions', + __DIR__ . '/../src/constants.php', + + ]); + + $services->alias(Application::class, ConsoleApplication::class); + + $services->set(EmptyConfigurableRectorCollector::class) + ->arg('$containerBuilder', service('service_container')); + + $services->set(SimpleCallableNodeTraverser::class); + + $services->set(BuilderFactory::class); + $services->set(CloningVisitor::class); + $services->set(NodeConnectingVisitor::class); + $services->set(NodeFinder::class); + + $services->set(RectorConsoleOutputStyle::class) + ->factory([service(RectorConsoleOutputStyleFactory::class), 'create']); + + $services->set(Parser::class) + ->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']); + + $services->set(Lexer::class) + ->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']); + + // symplify/package-builder + $services->set(FileSystemGuard::class); + $services->set(PrivatesAccessor::class); + $services->set(PrivatesCaller::class); + $services->set(FinderSanitizer::class); + $services->set(FileSystemFilter::class); + + $services->set(ParameterProvider::class) + ->arg('$container', service('service_container')); + + $services->set(SmartFileSystem::class); + $services->set(JsonFileSystem::class); + + $services->set(InflectorFactory::class); + $services->set(Inflector::class) + ->factory([service(InflectorFactory::class), 'build']); + + $services->set(VersionParser::class); + $services->set(TypeChecker::class); + + // phpdoc parser + $services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class); + $services->alias(PhpDocParser::class, BetterPhpDocParser::class); + + // cache + $services->set(DependencyResolver::class) + ->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']); + $services->set(FileHelper::class) + ->factory([service(PHPStanServicesFactory::class), 'createFileHelper']); + + $services->set(Cache::class) + ->factory([service(CacheFactory::class), 'create']); + + // type resolving + $services->set(IntermediateSourceLocator::class); + $services->alias(TypeParser::class, BetterTypeParser::class); + + // PHPStan services + $services->set(ReflectionProvider::class) + ->factory([service(PHPStanServicesFactory::class), 'createReflectionProvider']); + + $services->set(NodeScopeResolver::class) + ->factory([service(PHPStanServicesFactory::class), 'createNodeScopeResolver']); + + $services->set(ScopeFactory::class) + ->factory([service(PHPStanServicesFactory::class), 'createScopeFactory']); + + $services->set(TypeNodeResolver::class) + ->factory([service(PHPStanServicesFactory::class), 'createTypeNodeResolver']); + + $services->set(DynamicSourceLocatorProvider::class) + ->factory([service(PHPStanServicesFactory::class), 'createDynamicSourceLocatorProvider']); + + $services->set(EditorConfig::class); + + $services->set(Printer::class); + $services->alias(PrinterInterface::class, Printer::class); }; diff --git a/config/services-rules.php b/config/services-rules.php deleted file mode 100644 index 1a5a320cb8a..00000000000 --- a/config/services-rules.php +++ /dev/null @@ -1,29 +0,0 @@ -services(); - - $services->defaults() - ->public() - ->autowire() - ->autoconfigure(); - - // psr-4 - $services->alias(PSR4AutoloadNamespaceMatcherInterface::class, PSR4NamespaceMatcher::class); - - $services->load('Rector\\', __DIR__ . '/../rules') - ->exclude([ - __DIR__ . '/../rules/*/ValueObject/*', - __DIR__ . '/../rules/*/Rector/*', - __DIR__ . '/../rules/*/Contract/*', - __DIR__ . '/../rules/*/Exception/*', - __DIR__ . '/../rules/*/Enum/*', - __DIR__ . '/../rules/DowngradePhp80/Reflection/SimplePhpParameterReflection.php', - ]); -}; diff --git a/config/services.php b/config/services.php deleted file mode 100644 index 2aae629d95c..00000000000 --- a/config/services.php +++ /dev/null @@ -1,163 +0,0 @@ -services(); - - $services->defaults() - ->public() - ->autowire() - ->autoconfigure(); - - $services->load('Rector\Core\\', __DIR__ . '/../src') - ->exclude([ - __DIR__ . '/../src/Rector', - __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', - __DIR__ . '/../src/Exception', - __DIR__ . '/../src/DependencyInjection/CompilerPass', - __DIR__ . '/../src/DependencyInjection/Loader', - __DIR__ . '/../src/Kernel', - __DIR__ . '/../src/ValueObject', - __DIR__ . '/../src/Bootstrap', - __DIR__ . '/../src/Enum', - __DIR__ . '/../src/PhpParser/Node/CustomNode', - __DIR__ . '/../src/PhpParser/ValueObject', - __DIR__ . '/../src/functions', - __DIR__ . '/../src/constants.php', - - ]); - - $services->alias(Application::class, ConsoleApplication::class); - - $services->set(FileSystemGuard::class); - - $services->set(EmptyConfigurableRectorCollector::class) - ->arg('$containerBuilder', service('service_container')); - - $services->set(SimpleCallableNodeTraverser::class); - - $services->set(ParserFactory::class); - $services->set(BuilderFactory::class); - $services->set(CloningVisitor::class); - $services->set(NodeFinder::class); - - $services->set(RectorConsoleOutputStyle::class) - ->factory([service(RectorConsoleOutputStyleFactory::class), 'create']); - - $services->set(Parser::class) - ->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']); - - $services->set(Lexer::class) - ->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']); - - // symplify/package-builder - $services->set(PrivatesAccessor::class); - $services->set(PrivatesCaller::class); - $services->set(FinderSanitizer::class); - $services->set(FileSystemFilter::class); - - $services->set(ParameterProvider::class) - ->arg('$container', service('service_container')); - - $services->set(CommandNaming::class); - $services->set(SmartFileSystem::class); - - $services->set(StringFormatConverter::class); - - $services->set(JsonFileSystem::class); - $services->set(NodeConnectingVisitor::class); - - $services->set(InflectorFactory::class); - $services->set(Inflector::class) - ->factory([service(InflectorFactory::class), 'build']); - - $services->set(VersionParser::class); - $services->set(TypeChecker::class); - - // phpdoc parser - $services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class); - $services->alias(PhpDocParser::class, BetterPhpDocParser::class); - - // cache - $services->set(DependencyResolver::class) - ->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']); - $services->set(FileHelper::class) - ->factory([service(PHPStanServicesFactory::class), 'createFileHelper']); - - $services->set(Cache::class) - ->factory([service(CacheFactory::class), 'create']); - - // type resolving - $services->set(IntermediateSourceLocator::class); - $services->alias(TypeParser::class, BetterTypeParser::class); - - // PHPStan services - $services->set(ReflectionProvider::class) - ->factory([service(PHPStanServicesFactory::class), 'createReflectionProvider']); - - $services->set(NodeScopeResolver::class) - ->factory([service(PHPStanServicesFactory::class), 'createNodeScopeResolver']); - - $services->set(ScopeFactory::class) - ->factory([service(PHPStanServicesFactory::class), 'createScopeFactory']); - - $services->set(TypeNodeResolver::class) - ->factory([service(PHPStanServicesFactory::class), 'createTypeNodeResolver']); - - $services->set(DynamicSourceLocatorProvider::class) - ->factory([service(PHPStanServicesFactory::class), 'createDynamicSourceLocatorProvider']); - - $services->set(EditorConfig::class); - - $services->set(Printer::class); - $services->alias(PrinterInterface::class, Printer::class); -}; diff --git a/packages-tests/Parallel/Command/WorkerCommandLineFactoryTest.php b/packages-tests/Parallel/Command/WorkerCommandLineFactoryTest.php index 88baeed1411..b21af054511 100644 --- a/packages-tests/Parallel/Command/WorkerCommandLineFactoryTest.php +++ b/packages-tests/Parallel/Command/WorkerCommandLineFactoryTest.php @@ -8,13 +8,11 @@ use Iterator; use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\Core\Configuration\Option; use Rector\Core\Console\Command\ProcessCommand; -use Rector\Core\Console\Command\WorkerCommand; use Rector\Core\Kernel\RectorKernel; use Rector\Parallel\Command\WorkerCommandLineFactory; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; -use Symplify\PackageBuilder\Console\Command\CommandNaming; use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; final class WorkerCommandLineFactoryTest extends AbstractKernelTestCase @@ -53,7 +51,7 @@ final class WorkerCommandLineFactoryTest extends AbstractKernelTestCase $workerCommandLine = $this->workerCommandLineFactory->create( self::DUMMY_MAIN_SCRIPT, ProcessCommand::class, - CommandNaming::classToName(WorkerCommand::class), + 'worker', $arrayInput, 'identifier', 2000 diff --git a/packages/Config/RectorConfig.php b/packages/Config/RectorConfig.php index de74e4591d6..0c3ee1042fd 100644 --- a/packages/Config/RectorConfig.php +++ b/packages/Config/RectorConfig.php @@ -111,6 +111,7 @@ final class RectorConfig extends ContainerConfigurator */ public function ruleWithConfiguration(string $rectorClass, array $configuration): void { + Assert::classExists($rectorClass); Assert::isAOf($rectorClass, RectorInterface::class); Assert::isAOf($rectorClass, ConfigurableRectorInterface::class); @@ -134,6 +135,7 @@ final class RectorConfig extends ContainerConfigurator */ public function rule(string $rectorClass): void { + Assert::classExists($rectorClass); Assert::isAOf($rectorClass, RectorInterface::class); $services = $this->services(); diff --git a/packages/Parallel/Application/ParallelFileProcessor.php b/packages/Parallel/Application/ParallelFileProcessor.php index 1ee2f5ed778..6df87da67d3 100644 --- a/packages/Parallel/Application/ParallelFileProcessor.php +++ b/packages/Parallel/Application/ParallelFileProcessor.php @@ -12,7 +12,6 @@ use React\Socket\ConnectionInterface; use React\Socket\TcpServer; use Rector\Core\Configuration\Option; use Rector\Core\Console\Command\ProcessCommand; -use Rector\Core\Console\Command\WorkerCommand; use Rector\Core\ValueObject\Error\SystemError; use Rector\Core\ValueObject\Reporting\FileDiff; use Rector\Parallel\Command\WorkerCommandLineFactory; @@ -27,7 +26,6 @@ use Symplify\EasyParallel\Enum\ReactEvent; use Symplify\EasyParallel\ValueObject\ParallelProcess; use Symplify\EasyParallel\ValueObject\ProcessPool; use Symplify\EasyParallel\ValueObject\Schedule; -use Symplify\PackageBuilder\Console\Command\CommandNaming; use Symplify\PackageBuilder\Parameter\ParameterProvider; use Throwable; @@ -141,7 +139,7 @@ final class ParallelFileProcessor $workerCommandLine = $this->workerCommandLineFactory->create( $mainScript, ProcessCommand::class, - CommandNaming::classToName(WorkerCommand::class), + 'worker', $input, $processIdentifier, $serverPort, diff --git a/phpstan.neon b/phpstan.neon index ea2980a0840..fb1b7b4aeee 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -484,6 +484,7 @@ parameters: - rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php - rules/Php70/EregToPcreTransformer.php - rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php + - src/Kernel/RectorKernel.php - '#Method Rector\\Core\\Application\\ApplicationFileProcessor\:\:runParallel\(\) should return array\{system_errors\: array, file_diffs\: array\} but returns array#' @@ -694,4 +695,6 @@ parameters: - '#Parameter \#2 \$args of class PhpParser\\Node\\Expr\\FuncCall constructor expects array, array given#' # validate class-string input - - '#Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with class\-string and (.*?) will always evaluate to false#' + - + message: '#Call to static method Webmozart\\Assert\\Assert\:\:(.*?)\(\) with (.*?) will always evaluate to (false|true)#' + path: packages/Config/RectorConfig.php diff --git a/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php b/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php index c477aef8812..cd8e9a2ec86 100644 --- a/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php +++ b/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php @@ -7,8 +7,8 @@ namespace Rector\CodeQuality\Rector\Ternary; use PhpParser\Node; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Ternary; -use Rector\Core\PhpParser\Node\Value\TernaryBracketWrapper; use Rector\Core\Rector\AbstractRector; +use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -17,11 +17,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; */ final class SwitchNegatedTernaryRector extends AbstractRector { - public function __construct( - private readonly TernaryBracketWrapper $ternaryBracketWrapper - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -81,7 +76,9 @@ CODE_SAMPLE [$node->if, $node->else] = [$node->else, $node->if]; if ($node->if instanceof Ternary) { - $this->ternaryBracketWrapper->wrapWithBracket($node->if); + $ternary = $node->if; + $ternary->setAttribute(AttributeKey::KIND, 'wrapped_with_brackets'); + $ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null); } return $node; diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 7018b15daf8..fe8396aa8b4 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -4,12 +4,10 @@ declare(strict_types=1); namespace Rector\Core\Configuration; -use JetBrains\PhpStorm\Immutable; use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Symplify\Skipper\ValueObject\Option as SkipperOption; -#[Immutable] final class Option { /** diff --git a/src/Console/Command/InitCommand.php b/src/Console/Command/InitCommand.php index 2c83ba5e4c7..ba558562ac3 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Console/Command/InitCommand.php @@ -36,6 +36,8 @@ final class InitCommand extends Command protected function configure(): void { + $this->setName('init'); + $this->setDescription('Generate rector.php configuration file'); $this->addOption( diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 6738f44f8f1..e740101db0a 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -24,7 +24,6 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symplify\PackageBuilder\Console\Command\CommandNaming; use Symplify\SmartFileSystem\SmartFileInfo; final class ProcessCommand extends AbstractProcessCommand @@ -47,7 +46,7 @@ final class ProcessCommand extends AbstractProcessCommand protected function configure(): void { - $this->setName(CommandNaming::classToName(self::class)); + $this->setName('process'); $this->setDescription('Upgrades or refactors source code with provided rectors'); parent::configure(); diff --git a/src/Console/Command/WorkerCommand.php b/src/Console/Command/WorkerCommand.php index 00defca6238..68c76b41707 100644 --- a/src/Console/Command/WorkerCommand.php +++ b/src/Console/Command/WorkerCommand.php @@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symplify\EasyParallel\Enum\Action; use Symplify\EasyParallel\Enum\ReactCommand; -use Symplify\PackageBuilder\Console\Command\CommandNaming; /** * Inspired at: https://github.com/phpstan/phpstan-src/commit/9124c66dcc55a222e21b1717ba5f60771f7dda92 @@ -35,7 +34,7 @@ final class WorkerCommand extends AbstractProcessCommand protected function configure(): void { - $this->setName(CommandNaming::classToName(self::class)); + $this->setName('worker'); $this->setDescription('(Internal) Support for parallel process'); parent::configure(); } diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index 6ee59c6f557..d509c741744 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -28,15 +28,10 @@ final class ConsoleApplication extends Application /** * @param Command[] $commands */ - public function __construct(CommandNaming $commandNaming, array $commands = []) + public function __construct(array $commands = []) { parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION); - foreach ($commands as $command) { - $commandName = $commandNaming->resolveFromCommand($command); - $command->setName($commandName); - } - $this->addCommands($commands); $this->setDefaultCommand(CommandNaming::classToName(ProcessCommand::class)); } diff --git a/src/DependencyInjection/CompilerPass/VerifyRectorServiceExistsCompilerPass.php b/src/DependencyInjection/CompilerPass/VerifyRectorServiceExistsCompilerPass.php deleted file mode 100644 index f2e70c69647..00000000000 --- a/src/DependencyInjection/CompilerPass/VerifyRectorServiceExistsCompilerPass.php +++ /dev/null @@ -1,48 +0,0 @@ -getDefinitions() as $definition) { - $class = $definition->getClass(); - if ($class === null) { - continue; - } - - if (! \str_ends_with($class, 'Rector')) { - continue; - } - - if (! class_exists($class)) { - throw new ShouldNotHappenException( - sprintf( - 'Rector rule "%s" not found, please verify that the class exists and is autoloadable.', - $class - ) - ); - } - - if (! is_a($class, RectorInterface::class, true)) { - throw new ShouldNotHappenException( - sprintf( - 'Rector rule "%s" should extend "%s" or implement "%s".', - $class, - AbstractRector::class, - RectorInterface::class - ) - ); - } - } - } -} diff --git a/src/DependencyInjection/RectorContainerFactory.php b/src/DependencyInjection/RectorContainerFactory.php index 97cb95b8a70..5cae4ce3e29 100644 --- a/src/DependencyInjection/RectorContainerFactory.php +++ b/src/DependencyInjection/RectorContainerFactory.php @@ -34,7 +34,7 @@ final class RectorContainerFactory ); $symfonyStyle->warning($warningMessage); // to make message noticable - sleep(3); + sleep(5); } /** @var ChangedFilesDetector $changedFilesDetector */ diff --git a/src/FileSystem/FilesFinder.php b/src/FileSystem/FilesFinder.php index 0810f4b6e87..06e81a8d072 100644 --- a/src/FileSystem/FilesFinder.php +++ b/src/FileSystem/FilesFinder.php @@ -52,7 +52,6 @@ final class FilesFinder $filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source); $filePaths = $this->fileSystemFilter->filterFiles($filesAndDirectories); - $directories = $this->fileSystemFilter->filterDirectories($filesAndDirectories); $smartFileInfos = $this->unchangedFilesFilter->filterAndJoinWithDependentFileInfos($filePaths); diff --git a/src/FileSystem/FilesystemTweaker.php b/src/FileSystem/FilesystemTweaker.php index fb3ead51d00..fc29e376d9e 100644 --- a/src/FileSystem/FilesystemTweaker.php +++ b/src/FileSystem/FilesystemTweaker.php @@ -4,39 +4,8 @@ declare(strict_types=1); namespace Rector\Core\FileSystem; -use Symplify\SmartFileSystem\FileSystemGuard; - final class FilesystemTweaker { - public function __construct( - private readonly FileSystemGuard $fileSystemGuard - ) { - } - - /** - * This will turn paths like "src/Symfony/Component/*\/Tests" to existing directory paths - * - * @param string[] $directories - * @return string[] - */ - public function resolveDirectoriesWithFnmatch(array $directories): array - { - $absoluteDirectories = []; - foreach ($directories as $directory) { - // is fnmatch for directories - if (\str_contains($directory, '*')) { - $foundDirectories = $this->findDirectoriesInGlob($directory); - $absoluteDirectories = array_merge($absoluteDirectories, $foundDirectories); - } else { - // is classic directory - $this->fileSystemGuard->ensureDirectoryExists($directory, ''); - $absoluteDirectories[] = $directory; - } - } - - return $absoluteDirectories; - } - /** * This will turn paths like "src/Symfony/Component/*\/Tests" to existing directory paths * @@ -59,16 +28,6 @@ final class FilesystemTweaker return $absolutePathsFound; } - /** - * @return string[] - */ - private function findDirectoriesInGlob(string $directory): array - { - /** @var string[] $foundDirectories */ - $foundDirectories = (array) glob($directory, GLOB_ONLYDIR); - return $foundDirectories; - } - /** * @return string[] */ diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php index f2c38bac99f..025f2fba835 100644 --- a/src/Kernel/RectorKernel.php +++ b/src/Kernel/RectorKernel.php @@ -10,7 +10,6 @@ use Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector; use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass; use Rector\Core\DependencyInjection\CompilerPass\RemoveSkippedRectorsCompilerPass; -use Rector\Core\DependencyInjection\CompilerPass\VerifyRectorServiceExistsCompilerPass; use Rector\Core\Exception\ShouldNotHappenException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -87,8 +86,6 @@ final class RectorKernel implements LightKernelInterface // add all merged arguments of Rector services $compilerPasses[] = new MergeImportedRectorConfigureCallValuesCompilerPass($this->configureCallValuesCollector); - $compilerPasses[] = new VerifyRectorServiceExistsCompilerPass(); - $compilerPasses[] = new AutowireArrayParameterCompilerPass(); return $compilerPasses; @@ -99,14 +96,12 @@ final class RectorKernel implements LightKernelInterface */ private function createDefaultConfigFiles(): array { - $configFiles = []; - - $configFiles[] = __DIR__ . '/../../config/config.php'; - $configFiles[] = AstralConfig::FILE_PATH; - $configFiles[] = ComposerJsonManipulatorConfig::FILE_PATH; - $configFiles[] = SkipperConfig::FILE_PATH; - $configFiles[] = ConsoleColorDiffConfig::FILE_PATH; - - return $configFiles; + return [ + __DIR__ . '/../../config/config.php', + AstralConfig::FILE_PATH, + ComposerJsonManipulatorConfig::FILE_PATH, + SkipperConfig::FILE_PATH, + ConsoleColorDiffConfig::FILE_PATH, + ]; } } diff --git a/src/PhpParser/Node/Value/TernaryBracketWrapper.php b/src/PhpParser/Node/Value/TernaryBracketWrapper.php deleted file mode 100644 index 0faa445c8dd..00000000000 --- a/src/PhpParser/Node/Value/TernaryBracketWrapper.php +++ /dev/null @@ -1,17 +0,0 @@ -setAttribute(AttributeKey::KIND, 'wrapped_with_brackets'); - $ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } -} diff --git a/src/Validation/EmptyConfigurableRectorChecker.php b/src/Validation/EmptyConfigurableRectorChecker.php index 07f0c704591..29176811bbf 100644 --- a/src/Validation/EmptyConfigurableRectorChecker.php +++ b/src/Validation/EmptyConfigurableRectorChecker.php @@ -53,6 +53,6 @@ final class EmptyConfigurableRectorChecker } // to take time to absorb it - sleep(3); + sleep(5); } } diff --git a/src/ValueObject/Configuration.php b/src/ValueObject/Configuration.php index d425907b9ae..dac76b1f37f 100644 --- a/src/ValueObject/Configuration.php +++ b/src/ValueObject/Configuration.php @@ -4,10 +4,8 @@ declare(strict_types=1); namespace Rector\Core\ValueObject; -use JetBrains\PhpStorm\Immutable; use Rector\ChangesReporting\Output\ConsoleOutputFormatter; -#[Immutable] final class Configuration { /** diff --git a/src/ValueObject/PhpVersion.php b/src/ValueObject/PhpVersion.php index 6efe986c2fc..741dc16e48a 100644 --- a/src/ValueObject/PhpVersion.php +++ b/src/ValueObject/PhpVersion.php @@ -6,88 +6,77 @@ namespace Rector\Core\ValueObject; use MyCLabs\Enum\Enum; +/** + * @api + */ final class PhpVersion extends Enum { /** - * @api * @var int */ public const PHP_52 = 50200; /** - * @api * @var int */ public const PHP_53 = 50300; /** - * @api * @var int */ public const PHP_54 = 50400; /** - * @api * @var int */ public const PHP_55 = 50500; /** - * @api * @var int */ public const PHP_56 = 50600; /** - * @api * @var int */ public const PHP_70 = 70000; /** - * @api * @var int */ public const PHP_71 = 70100; /** - * @api * @var int */ public const PHP_72 = 70200; /** - * @api * @var int */ public const PHP_73 = 70300; /** - * @api * @var int */ public const PHP_74 = 70400; /** - * @api * @var int */ public const PHP_80 = 80000; /** - * @api * @var int */ public const PHP_81 = 80100; /** - * @api * @var int */ public const PHP_82 = 80200; /** - * @api * @var int */ public const PHP_10 = 100000; diff --git a/src/ValueObject/RectifiedNode.php b/src/ValueObject/RectifiedNode.php index 3bf1eae7a85..0c0405be72b 100644 --- a/src/ValueObject/RectifiedNode.php +++ b/src/ValueObject/RectifiedNode.php @@ -5,15 +5,22 @@ declare(strict_types=1); namespace Rector\Core\ValueObject; use PhpParser\Node; +use Rector\Core\Contract\Rector\RectorInterface; final class RectifiedNode { + /** + * @param class-string $rectorClass + */ public function __construct( private readonly string $rectorClass, private readonly Node $node ) { } + /** + * @return class-string + */ public function getRectorClass(): string { return $this->rectorClass;