diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 073abc3f0ad..07ea2e04c44 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '7ad142473531a56d8eb6d9d7571f0d77b0661fbf'; + public const PACKAGE_VERSION = '7fc9494a41eefd94af850b47d8af78f322a7884c'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-01-05 09:23:30'; + public const RELEASE_DATE = '2025-01-05 09:59:18'; /** * @var int */ diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 3e773fa74e9..b2c0294150e 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -33,7 +33,7 @@ final class ConfigurationFactory public function createForTests(array $paths) : Configuration { $fileExtensions = SimpleParameterProvider::provideArrayParameter(\Rector\Configuration\Option::FILE_EXTENSIONS); - return new Configuration(\false, \true, \false, ConsoleOutputFormatter::NAME, $fileExtensions, $paths, \true, null, null, \false, null, \false, \false, null); + return new Configuration(\false, \true, \false, ConsoleOutputFormatter::NAME, $fileExtensions, $paths, \true, null, null, \false, null, \false, \false, null, null); } /** * Needs to run in the start of the life cycle, since the rest of workflow uses it. @@ -47,10 +47,12 @@ final class ConfigurationFactory $showDiffs = $this->shouldShowDiffs($input); $paths = $this->resolvePaths($input); $fileExtensions = SimpleParameterProvider::provideArrayParameter(\Rector\Configuration\Option::FILE_EXTENSIONS); + // filter rule and path $onlyRule = $input->getOption(\Rector\Configuration\Option::ONLY); if ($onlyRule !== null) { $onlyRule = $this->onlyRuleResolver->resolve($onlyRule); } + $onlySuffix = $input->getOption(\Rector\Configuration\Option::ONLY_SUFFIX); $isParallel = SimpleParameterProvider::provideBoolParameter(\Rector\Configuration\Option::PARALLEL); $parallelPort = (string) $input->getOption(\Rector\Configuration\Option::PARALLEL_PORT); $parallelIdentifier = (string) $input->getOption(\Rector\Configuration\Option::PARALLEL_IDENTIFIER); @@ -61,7 +63,7 @@ final class ConfigurationFactory } $memoryLimit = $this->resolveMemoryLimit($input); $isReportingWithRealPath = SimpleParameterProvider::provideBoolParameter(\Rector\Configuration\Option::ABSOLUTE_FILE_PATH); - return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRule); + return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRule, $onlySuffix); } private function shouldShowProgressBar(InputInterface $input, string $outputFormat) : bool { diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 3e735b2ff6f..5d1fa44c06d 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -232,4 +232,8 @@ final class Option * @var string */ public const COMPOSER_BASED_SETS = 'composer_based_sets'; + /** + * @internal To filter files by specific suffix + */ + public const ONLY_SUFFIX = 'only-suffix'; } diff --git a/src/Console/ProcessConfigureDecorator.php b/src/Console/ProcessConfigureDecorator.php index a93f2f4213d..ff8a172249a 100644 --- a/src/Console/ProcessConfigureDecorator.php +++ b/src/Console/ProcessConfigureDecorator.php @@ -18,7 +18,9 @@ final class ProcessConfigureDecorator $command->addOption(Option::NO_PROGRESS_BAR, null, InputOption::VALUE_NONE, 'Hide progress bar. Useful e.g. for nicer CI output.'); $command->addOption(Option::NO_DIFFS, null, InputOption::VALUE_NONE, 'Hide diffs of changed files. Useful e.g. for nicer CI output.'); $command->addOption(Option::OUTPUT_FORMAT, null, InputOption::VALUE_REQUIRED, 'Select output format', ConsoleOutputFormatter::NAME); + // filter by rule and path $command->addOption(Option::ONLY, null, InputOption::VALUE_REQUIRED, 'Fully qualified rule class name'); + $command->addOption(Option::ONLY_SUFFIX, null, InputOption::VALUE_REQUIRED, 'Filter only files with specific suffix in name, e.g. "Controller"'); $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/FileSystem/FilesFinder.php b/src/FileSystem/FilesFinder.php index 105fb9c4a83..2009c21616a 100644 --- a/src/FileSystem/FilesFinder.php +++ b/src/FileSystem/FilesFinder.php @@ -54,7 +54,7 @@ final class FilesFinder * @param string[] $suffixes * @return string[] */ - public function findInDirectoriesAndFiles(array $source, array $suffixes = [], bool $sortByName = \true) : array + public function findInDirectoriesAndFiles(array $source, array $suffixes = [], bool $sortByName = \true, ?string $onlySuffix = null) : array { $filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source); // filtering files in files collection @@ -77,7 +77,7 @@ final class FilesFinder }); // filtering files in directories collection $directories = $this->fileAndDirectoryFilter->filterDirectories($filesAndDirectories); - $filteredFilePathsInDirectories = $this->findInDirectories($directories, $suffixes, $sortByName); + $filteredFilePathsInDirectories = $this->findInDirectories($directories, $suffixes, $sortByName, $onlySuffix); $filePaths = \array_merge($filteredFilePaths, $filteredFilePathsInDirectories); return $this->unchangedFilesFilter->filterFilePaths($filePaths); } @@ -90,8 +90,7 @@ final class FilesFinder if ($configuration->shouldClearCache()) { $this->changedFilesDetector->clear(); } - $supportedFileExtensions = $configuration->getFileExtensions(); - return $this->findInDirectoriesAndFiles($paths, $supportedFileExtensions); + return $this->findInDirectoriesAndFiles($paths, $configuration->getFileExtensions(), \true, $configuration->getOnlySuffix()); } /** * Exclude short "sortByName(); } - if ($suffixes !== []) { + // filter files by specific suffix + if ($onlySuffix !== null && $onlySuffix !== '') { + if (\substr_compare($onlySuffix, '.php', -\strlen('.php')) !== 0) { + $onlySuffix .= '.php'; + } + $finder->name('*' . $onlySuffix); + } elseif ($suffixes !== []) { $suffixesPattern = $this->normalizeSuffixesToPattern($suffixes); $finder->name($suffixesPattern); } diff --git a/src/ValueObject/Configuration.php b/src/ValueObject/Configuration.php index 459828ae442..bbdc52e3dbc 100644 --- a/src/ValueObject/Configuration.php +++ b/src/ValueObject/Configuration.php @@ -68,11 +68,15 @@ final class Configuration * @readonly */ private ?string $onlyRule = null; + /** + * @readonly + */ + private ?string $onlySuffix = null; /** * @param string[] $fileExtensions * @param string[] $paths */ - public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, ?string $parallelPort = null, ?string $parallelIdentifier = null, bool $isParallel = \false, ?string $memoryLimit = null, bool $isDebug = \false, bool $reportingWithRealPath = \false, ?string $onlyRule = null) + public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, ?string $parallelPort = null, ?string $parallelIdentifier = null, bool $isParallel = \false, ?string $memoryLimit = null, bool $isDebug = \false, bool $reportingWithRealPath = \false, ?string $onlyRule = null, ?string $onlySuffix = null) { $this->isDryRun = $isDryRun; $this->showProgressBar = $showProgressBar; @@ -88,6 +92,7 @@ final class Configuration $this->isDebug = $isDebug; $this->reportingWithRealPath = $reportingWithRealPath; $this->onlyRule = $onlyRule; + $this->onlySuffix = $onlySuffix; } public function isDryRun() : bool { @@ -152,4 +157,8 @@ final class Configuration { return $this->reportingWithRealPath; } + public function getOnlySuffix() : ?string + { + return $this->onlySuffix; + } }