mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-16 13:00:23 +01:00
Updated Rector to commit 7fc9494a41eefd94af850b47d8af78f322a7884c
7fc9494a41
[dx] Add --only-suffix to filter files by suffixes (#6647)
This commit is contained in:
parent
d7d4304a20
commit
ea61794d69
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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 "<?=" tags as lead to invalid changes
|
||||
@ -105,7 +104,7 @@ final class FilesFinder
|
||||
* @param string[] $suffixes
|
||||
* @return string[]
|
||||
*/
|
||||
private function findInDirectories(array $directories, array $suffixes, bool $sortByName = \true) : array
|
||||
private function findInDirectories(array $directories, array $suffixes, bool $sortByName = \true, ?string $onlySuffix = null) : array
|
||||
{
|
||||
if ($directories === []) {
|
||||
return [];
|
||||
@ -114,7 +113,13 @@ final class FilesFinder
|
||||
if ($sortByName) {
|
||||
$finder->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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user