diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 8aab0d0f9f7..f45dc8cf8f5 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -38,7 +38,6 @@ jobs: - 'e2e/only-option-quote-single-bsdouble' - 'e2e/only-option-quote-single-equalnone' - 'e2e/parallel-custom-config' - - 'e2e/parallel-kaizen-applied-rules' - 'e2e/parallel-reflection-resolver' - 'e2e/parallel with space' - 'e2e/print-new-node' @@ -71,10 +70,6 @@ jobs: working-directory: ${{ matrix.directory }} if: ${{ matrix.directory == 'e2e/parallel-custom-config' }} - - run: php ../e2eTestRunner.php --kaizen 1 - working-directory: ${{ matrix.directory }} - if: ${{ matrix.directory == 'e2e/parallel-kaizen-applied-rules' }} - - run: php ../e2eTestRunner.php working-directory: ${{ matrix.directory }} - if: ${{ matrix.directory != 'e2e/parallel-custom-config' && matrix.directory != 'e2e/parallel-kaizen-applied-rules' }} + if: ${{ matrix.directory != 'e2e/parallel-custom-config' }} diff --git a/.github/workflows/e2e_command_with_option.yaml b/.github/workflows/e2e_command_with_option.yaml index cf680634eef..7b38a6d75de 100644 --- a/.github/workflows/e2e_command_with_option.yaml +++ b/.github/workflows/e2e_command_with_option.yaml @@ -40,23 +40,24 @@ jobs: php ../../bin/rector help # with explicit "process" command - ../../bin/rector process --kaizen 1 --dry-run - ../../bin/rector process --kaizen=1 --dry-run - php ../../bin/rector process --kaizen 1 --dry-run - php ../../bin/rector process --kaizen=1 --dry-run - ../../bin/rector process some_file.php --kaizen 1 - ../../bin/rector process some_file.php --kaizen=1 - php ../../bin/rector process some_file.php --kaizen 1 - php ../../bin/rector process some_file.php --kaizen=1 + ../../bin/rector process --output-format json --dry-run + ../../bin/rector process --output-format=json --dry-run + php ../../bin/rector process --output-format json --dry-run + php ../../bin/rector process --output-format=json --dry-run + + ../../bin/rector process some_file.php --output-format json + ../../bin/rector process some_file.php --output-format=json + php ../../bin/rector process some_file.php --output-format json + php ../../bin/rector process some_file.php --output-format=json # with implicit process command - ../../bin/rector --kaizen 1 --dry-run - ../../bin/rector --kaizen=1 --dry-run - php ../../bin/rector --kaizen 1 --dry-run - php ../../bin/rector --kaizen=1 --dry-run - - ../../bin/rector some_file.php --kaizen 1 - ../../bin/rector some_file.php --kaizen=1 - php ../../bin/rector some_file.php --kaizen 1 - php ../../bin/rector some_file.php --kaizen=1 + ../../bin/rector --output-format json --dry-run + ../../bin/rector --output-format=json --dry-run + php ../../bin/rector --output-format json --dry-run + php ../../bin/rector --output-format=json --dry-run + + ../../bin/rector some_file.php --output-format json + ../../bin/rector some_file.php --output-format=json + php ../../bin/rector some_file.php --output-format json + php ../../bin/rector some_file.php --output-format=json diff --git a/e2e/e2eTestRunner.php b/e2e/e2eTestRunner.php index e99630b161f..1facf046b3c 100644 --- a/e2e/e2eTestRunner.php +++ b/e2e/e2eTestRunner.php @@ -32,10 +32,6 @@ $e2eCommand .= ' -a ' . $argv[2]; } -if (isset($argv[1]) && $argv[1] === '--kaizen') { - $e2eCommand .= ' --kaizen ' . $argv[2]; -} - $cliOptions = 'cli-options.txt'; if (file_exists($cliOptions)) { $e2eCommand .= ' ' . trim((string) file_get_contents($cliOptions)); diff --git a/e2e/parallel-kaizen-applied-rules/.gitignore b/e2e/parallel-kaizen-applied-rules/.gitignore deleted file mode 100644 index 61ead86667c..00000000000 --- a/e2e/parallel-kaizen-applied-rules/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/vendor diff --git a/e2e/parallel-kaizen-applied-rules/composer.json b/e2e/parallel-kaizen-applied-rules/composer.json deleted file mode 100644 index 8b5ca727be7..00000000000 --- a/e2e/parallel-kaizen-applied-rules/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "php": "^8.1" - } -} diff --git a/e2e/parallel-kaizen-applied-rules/expected-output.diff b/e2e/parallel-kaizen-applied-rules/expected-output.diff deleted file mode 100644 index d04a2a663fe..00000000000 --- a/e2e/parallel-kaizen-applied-rules/expected-output.diff +++ /dev/null @@ -1,36 +0,0 @@ -[EXPERIMENTAL] Running Kaizen mode. Only first 1 rule will be applied - -2 files with changes -==================== - -1) src/File1.php:6 - - ---------- begin diff ---------- -@@ @@ - - final class File1 - { -- private $foo; - } - ----------- end diff ----------- - -Applied rules: - * RemoveUnusedPrivatePropertyRector - - -2) src/File3.php:6 - - ---------- begin diff ---------- -@@ @@ - - final class File3 - { -- private $foo; - } - ----------- end diff ----------- - -Applied rules: - * RemoveUnusedPrivatePropertyRector - - - [OK] 2 files would have been changed (dry-run) by Rector \ No newline at end of file diff --git a/e2e/parallel-kaizen-applied-rules/rector.php b/e2e/parallel-kaizen-applied-rules/rector.php deleted file mode 100644 index c9d34dfc5dd..00000000000 --- a/e2e/parallel-kaizen-applied-rules/rector.php +++ /dev/null @@ -1,23 +0,0 @@ -parallel(maxNumberOfProcess: 2, jobSize: 1); - $rectorConfig->cacheClass(FileCacheStorage::class); - $rectorConfig->cacheDirectory(sys_get_temp_dir() . '/rector'); - - $rectorConfig->paths([ - __DIR__ . '/src/', - ]); - - $rectorConfig->rules([ - RemoveUnusedPrivatePropertyRector::class, - RemoveUnusedPrivateMethodRector::class, - ]); -}; diff --git a/e2e/parallel-kaizen-applied-rules/src/File1.php b/e2e/parallel-kaizen-applied-rules/src/File1.php deleted file mode 100644 index 4a70bad12ad..00000000000 --- a/e2e/parallel-kaizen-applied-rules/src/File1.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(AddParamStringTypeFromSprintfUseRector::class); diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector.php index ae658b909c8..016c7ac0e7e 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector.php @@ -4,8 +4,8 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; -use PhpParser\Node\Identifier; use PhpParser\Node; +use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Rector\AbstractRector; diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index baeb38e22c6..a9bff22b3b1 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -8,7 +8,6 @@ use PHPStan\Parser\ParserErrorsException; use Rector\Application\Provider\CurrentFileProvider; use Rector\Caching\Detector\ChangedFilesDetector; -use Rector\Configuration\KaizenStepper; use Rector\Configuration\Option; use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\FileSystem\FilesFinder; @@ -53,7 +52,6 @@ public function __construct( private readonly FileProcessor $fileProcessor, private readonly ArrayParametersMerger $arrayParametersMerger, private readonly MissConfigurationReporter $missConfigurationReporter, - private readonly KaizenStepper $kaizenStepper ) { } @@ -120,10 +118,6 @@ public function processFiles( ?callable $preFileCallback = null, ?callable $postFileCallback = null ): ProcessResult { - if ($configuration->isKaizenEnabled()) { - $this->kaizenStepper->setStepCount($configuration->getKaizenStepCount()); - } - /** @var SystemError[] $systemErrors */ $systemErrors = []; diff --git a/src/Caching/Detector/KaizenRulesDetector.php b/src/Caching/Detector/KaizenRulesDetector.php deleted file mode 100644 index 2a9f898f92f..00000000000 --- a/src/Caching/Detector/KaizenRulesDetector.php +++ /dev/null @@ -1,48 +0,0 @@ -loadRules(); - - $appliedRectorClasses = array_unique(array_merge($cachedValue, [$rectorClass])); - $this->cache->save($this->getCacheKey(), CacheKey::KAIZEN_RULES, $appliedRectorClasses); - } - - /** - * @return array> - */ - public function loadRules(): array - { - $key = $this->getCacheKey(); - $rules = $this->cache->load($key, CacheKey::KAIZEN_RULES) ?? []; - - if (! is_array($rules)) { - throw new ShouldNotHappenException(); - } - - return array_unique($rules); - } - - private function getCacheKey(): string - { - return CacheKey::KAIZEN_RULES . '_' . $this->fileHasher->hash(getcwd()); - } -} diff --git a/src/Caching/Enum/CacheKey.php b/src/Caching/Enum/CacheKey.php index bfcb377ec48..66512c05905 100644 --- a/src/Caching/Enum/CacheKey.php +++ b/src/Caching/Enum/CacheKey.php @@ -18,9 +18,4 @@ final class CacheKey * @var string */ public const FILE_HASH_KEY = 'file_hash'; - - /** - * @var string - */ - public const KAIZEN_RULES = 'kaizen_rules'; } diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 099267fd473..70a699f8801 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -9,7 +9,6 @@ use Rector\ValueObject\Configuration; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Webmozart\Assert\Assert; /** * @see \Rector\Tests\Configuration\ConfigurationFactoryTest @@ -58,13 +57,6 @@ public function createFromInput(InputInterface $input): Configuration $shouldClearCache = (bool) $input->getOption(Option::CLEAR_CACHE); $outputFormat = (string) $input->getOption(Option::OUTPUT_FORMAT); - - $kaizenStepCount = $input->getOption(Option::KAIZEN); - if ($kaizenStepCount !== null) { - $kaizenStepCount = (int) $kaizenStepCount; - Assert::positiveInteger($kaizenStepCount, 'Change "--kaizen" value to a positive integer'); - } - $showProgressBar = $this->shouldShowProgressBar($input, $outputFormat); $showDiffs = $this->shouldShowDiffs($input); @@ -114,7 +106,6 @@ public function createFromInput(InputInterface $input): Configuration $onlyRule, $onlySuffix, $levelOverflows, - $kaizenStepCount ); } diff --git a/src/Configuration/KaizenStepper.php b/src/Configuration/KaizenStepper.php deleted file mode 100644 index 56f28b6b0eb..00000000000 --- a/src/Configuration/KaizenStepper.php +++ /dev/null @@ -1,55 +0,0 @@ -stepCount = $stepCount; - } - - public function enabled(): bool - { - return $this->stepCount !== null; - } - - /** - * @param class-string $rectorClass - */ - public function recordAppliedRule(string $rectorClass): void - { - $this->kaizenRulesDetector->addRule($rectorClass); - } - - public function shouldKeepImproving(string $rectorClass): bool - { - $appliedRectorClasses = $this->kaizenRulesDetector->loadRules(); - - // is rule already in applied rules? keep going - if (in_array($rectorClass, $appliedRectorClasses)) { - return true; - } - - // make sure we made enough changes - return count($appliedRectorClasses) < $this->stepCount; - } -} diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 2df4a0a0d44..30f2d3d794c 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -318,13 +318,4 @@ final class Option * @internal to allow process file without extension if explicitly registered */ public const FILES_WITHOUT_EXTENSION = 'files_without_extension'; - - /** - * @experimental - * - * Limit changes to first X applied rules - * - * @var string - */ - public const KAIZEN = 'kaizen'; } diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 14b7754f8df..c77ddac6427 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -87,15 +87,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $configuration = $this->configurationFactory->createFromInput($input); - if ($configuration->isKaizenEnabled()) { - $this->symfonyStyle->writeln(sprintf( - '[EXPERIMENTAL] Running Kaizen mode. Only first %d rule%s will be applied', - $configuration->getKaizenStepCount(), - $configuration->getKaizenStepCount() > 1 ? 's' : '' - )); - - $this->symfonyStyle->newLine(1); - } $this->memoryLimiter->adjust($configuration); $this->configurationRuleFilter->setConfiguration($configuration); diff --git a/src/Console/ProcessConfigureDecorator.php b/src/Console/ProcessConfigureDecorator.php index c50ed654921..7f5d3dab9bc 100644 --- a/src/Console/ProcessConfigureDecorator.php +++ b/src/Console/ProcessConfigureDecorator.php @@ -66,13 +66,6 @@ public static function decorate(Command $command): void 'Filter only files with specific suffix in name, e.g. "Controller"' ); - $command->addOption( - Option::KAIZEN, - null, - InputOption::VALUE_REQUIRED, - 'Improve step by step: apply only first X rules that make a change', - ); - $command->addOption(Option::DEBUG, null, InputOption::VALUE_NONE, 'Display debug output.'); $command->addOption(Option::MEMORY_LIMIT, null, InputOption::VALUE_REQUIRED, 'Memory limit for process'); $command->addOption(Option::CLEAR_CACHE, null, InputOption::VALUE_NONE, 'Clear unchanged files cache'); diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index 19d8e424c75..a63c3dc274b 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -53,7 +53,6 @@ use Rector\Config\RectorConfig; use Rector\Configuration\ConfigInitializer; use Rector\Configuration\ConfigurationRuleFilter; -use Rector\Configuration\KaizenStepper; use Rector\Configuration\OnlyRuleResolver; use Rector\Configuration\RenamedClassesDataCollector; use Rector\Console\Command\CustomRuleCommand; @@ -548,7 +547,6 @@ static function (AbstractRector $rector, Container $container): void { $container->get(CurrentFileProvider::class), $container->get(CreatedByRuleDecorator::class), $container->get(ChangedNodeScopeRefresher::class), - $container->get(KaizenStepper::class), ); } ); diff --git a/src/FileSystem/FilesFinder.php b/src/FileSystem/FilesFinder.php index 1f9a1a6d305..e1fbb410ec5 100644 --- a/src/FileSystem/FilesFinder.php +++ b/src/FileSystem/FilesFinder.php @@ -38,7 +38,6 @@ public function findInDirectoriesAndFiles( array $suffixes = [], bool $sortByName = true, ?string $onlySuffix = null, - bool $isKaizenEnabled = false ): array { $filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source); @@ -110,14 +109,6 @@ function (string $file): bool { return []; } - if ($isKaizenEnabled) { - // enforce clear cache, because there is probably another files that - // incrementally need to apply change on kaizen run - $this->changedFilesDetector->clear(); - - return array_unique($filePaths); - } - return $toBeChangedFiles; } @@ -136,7 +127,6 @@ public function findFilesInPaths(array $paths, Configuration $configuration): ar $configuration->getFileExtensions(), true, $configuration->getOnlySuffix(), - $configuration->isKaizenEnabled() ); } diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 1bafa3a307c..8ac5062f7a5 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -24,7 +24,6 @@ use Rector\Application\Provider\CurrentFileProvider; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; -use Rector\Configuration\KaizenStepper; use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Exception\ShouldNotHappenException; @@ -82,8 +81,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter private ?int $toBeRemovedNodeId = null; - private KaizenStepper $kaizenStepper; - public function autowire( NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, @@ -93,8 +90,7 @@ public function autowire( NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, CreatedByRuleDecorator $createdByRuleDecorator, - ChangedNodeScopeRefresher $changedNodeScopeRefresher, - KaizenStepper $kaizenStepper + ChangedNodeScopeRefresher $changedNodeScopeRefresher ): void { $this->nodeNameResolver = $nodeNameResolver; $this->nodeTypeResolver = $nodeTypeResolver; @@ -105,7 +101,6 @@ public function autowire( $this->currentFileProvider = $currentFileProvider; $this->createdByRuleDecorator = $createdByRuleDecorator; $this->changedNodeScopeRefresher = $changedNodeScopeRefresher; - $this->kaizenStepper = $kaizenStepper; } /** @@ -136,11 +131,6 @@ final public function enterNode(Node $node): int|Node|null return null; } - // should keep improving? - if ($this->kaizenStepper->enabled() && ! $this->kaizenStepper->shouldKeepImproving(static::class)) { - return null; - } - $filePath = $this->file->getFilePath(); if ($this->skipper->shouldSkipCurrentNode($this, $filePath, static::class, $node)) { return null; @@ -182,11 +172,6 @@ final public function enterNode(Node $node): int|Node|null } } - // take it step by step - if ($this->kaizenStepper->enabled()) { - $this->kaizenStepper->recordAppliedRule(static::class); - } - if ($isIntRefactoredNode) { // @see NodeVisitor::* codes, e.g. removal of node of stopping the traversing if ($refactoredNode === NodeVisitor::REMOVE_NODE) { diff --git a/src/ValueObject/Configuration.php b/src/ValueObject/Configuration.php index ba0e3e2c9d2..fbafc385f6f 100644 --- a/src/ValueObject/Configuration.php +++ b/src/ValueObject/Configuration.php @@ -16,7 +16,6 @@ * @param string[] $fileExtensions * @param string[] $paths * @param LevelOverflow[] $levelOverflows - * @param positive-int|null $kaizenStepCount */ public function __construct( private bool $isDryRun = false, @@ -35,11 +34,7 @@ public function __construct( private ?string $onlyRule = null, private ?string $onlySuffix = null, private array $levelOverflows = [], - private ?int $kaizenStepCount = null, ) { - if (is_int($kaizenStepCount)) { - Assert::positiveInteger($kaizenStepCount, 'Change "--kaizen" value to a positive integer'); - } } public function isDryRun(): bool @@ -146,19 +141,4 @@ public function getBothSetAndRulesDuplicatedRegistrations(): array return array_unique($ruleDuplicatedRegistrations); } - - /** - * @return positive-int - */ - public function getKaizenStepCount(): int - { - Assert::notNull($this->kaizenStepCount); - - return $this->kaizenStepCount; - } - - public function isKaizenEnabled(): bool - { - return $this->kaizenStepCount !== null; - } }