mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
Updated Rector to commit c02e5294b647a2aa7d83c8b2381dffbc7768b428
c02e5294b6
[Performance] Using PathSkipper in FilesFinder (#5452)
This commit is contained in:
parent
b68c88f0b4
commit
969e0174a1
|
@ -10,7 +10,6 @@ use Rector\Configuration\Option;
|
|||
use Rector\Configuration\Parameter\SimpleParameterProvider;
|
||||
use Rector\Parallel\Application\ParallelFileProcessor;
|
||||
use Rector\Provider\CurrentFileProvider;
|
||||
use Rector\Skipper\Skipper\PathSkipper;
|
||||
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
||||
use Rector\Util\ArrayParametersMerger;
|
||||
use Rector\ValueObject\Application\File;
|
||||
|
@ -73,11 +72,6 @@ final class ApplicationFileProcessor
|
|||
* @var \Rector\Util\ArrayParametersMerger
|
||||
*/
|
||||
private $arrayParametersMerger;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Skipper\PathSkipper
|
||||
*/
|
||||
private $pathSkipper;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -86,7 +80,7 @@ final class ApplicationFileProcessor
|
|||
* @var SystemError[]
|
||||
*/
|
||||
private $systemErrors = [];
|
||||
public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, \Rector\Application\FileProcessor $fileProcessor, ArrayParametersMerger $arrayParametersMerger, PathSkipper $pathSkipper)
|
||||
public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, \Rector\Application\FileProcessor $fileProcessor, ArrayParametersMerger $arrayParametersMerger)
|
||||
{
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
$this->fileFactory = $fileFactory;
|
||||
|
@ -97,7 +91,6 @@ final class ApplicationFileProcessor
|
|||
$this->currentFileProvider = $currentFileProvider;
|
||||
$this->fileProcessor = $fileProcessor;
|
||||
$this->arrayParametersMerger = $arrayParametersMerger;
|
||||
$this->pathSkipper = $pathSkipper;
|
||||
}
|
||||
public function run(Configuration $configuration, InputInterface $input) : ProcessResult
|
||||
{
|
||||
|
@ -152,9 +145,6 @@ final class ApplicationFileProcessor
|
|||
/** @var CollectedData[] $collectedData */
|
||||
$collectedData = [];
|
||||
foreach ($filePaths as $filePath) {
|
||||
if ($this->pathSkipper->shouldSkip($filePath)) {
|
||||
continue;
|
||||
}
|
||||
if ($preFileCallback !== null) {
|
||||
$preFileCallback($filePath);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f68d9f89cece7c081c431ddeeafe2d317514a1cc';
|
||||
public const PACKAGE_VERSION = 'c02e5294b647a2aa7d83c8b2381dffbc7768b428';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-10 14:01:07';
|
||||
public const RELEASE_DATE = '2024-01-10 21:02:07';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -4,10 +4,8 @@ declare (strict_types=1);
|
|||
namespace Rector\FileSystem;
|
||||
|
||||
use Rector\Caching\UnchangedFilesFilter;
|
||||
use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
||||
use Rector\Util\StringUtils;
|
||||
use Rector\Skipper\Skipper\PathSkipper;
|
||||
use RectorPrefix202401\Symfony\Component\Finder\Finder;
|
||||
use RectorPrefix202401\Symfony\Component\Finder\SplFileInfo;
|
||||
/**
|
||||
* @see \Rector\Tests\FileSystem\FilesFinder\FilesFinderTest
|
||||
*/
|
||||
|
@ -18,11 +16,6 @@ final class FilesFinder
|
|||
* @var \Rector\FileSystem\FilesystemTweaker
|
||||
*/
|
||||
private $filesystemTweaker;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver
|
||||
*/
|
||||
private $skippedPathsResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Caching\UnchangedFilesFilter
|
||||
|
@ -33,12 +26,17 @@ final class FilesFinder
|
|||
* @var \Rector\FileSystem\FileAndDirectoryFilter
|
||||
*/
|
||||
private $fileAndDirectoryFilter;
|
||||
public function __construct(\Rector\FileSystem\FilesystemTweaker $filesystemTweaker, SkippedPathsResolver $skippedPathsResolver, UnchangedFilesFilter $unchangedFilesFilter, \Rector\FileSystem\FileAndDirectoryFilter $fileAndDirectoryFilter)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Skipper\PathSkipper
|
||||
*/
|
||||
private $pathSkipper;
|
||||
public function __construct(\Rector\FileSystem\FilesystemTweaker $filesystemTweaker, UnchangedFilesFilter $unchangedFilesFilter, \Rector\FileSystem\FileAndDirectoryFilter $fileAndDirectoryFilter, PathSkipper $pathSkipper)
|
||||
{
|
||||
$this->filesystemTweaker = $filesystemTweaker;
|
||||
$this->skippedPathsResolver = $skippedPathsResolver;
|
||||
$this->unchangedFilesFilter = $unchangedFilesFilter;
|
||||
$this->fileAndDirectoryFilter = $fileAndDirectoryFilter;
|
||||
$this->pathSkipper = $pathSkipper;
|
||||
}
|
||||
/**
|
||||
* @param string[] $source
|
||||
|
@ -49,8 +47,11 @@ final class FilesFinder
|
|||
{
|
||||
$filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source);
|
||||
$filePaths = $this->fileAndDirectoryFilter->filterFiles($filesAndDirectories);
|
||||
$directories = $this->fileAndDirectoryFilter->filterDirectories($filesAndDirectories);
|
||||
$filePaths = \array_filter($filePaths, function (string $filePath) : bool {
|
||||
return !$this->pathSkipper->shouldSkip($filePath);
|
||||
});
|
||||
$currentAndDependentFilePaths = $this->unchangedFilesFilter->filterFileInfos($filePaths);
|
||||
$directories = $this->fileAndDirectoryFilter->filterDirectories($filesAndDirectories);
|
||||
return \array_merge($currentAndDependentFilePaths, $this->findInDirectories($directories, $suffixes, $sortByName));
|
||||
}
|
||||
/**
|
||||
|
@ -71,16 +72,19 @@ final class FilesFinder
|
|||
$suffixesPattern = $this->normalizeSuffixesToPattern($suffixes);
|
||||
$finder->name($suffixesPattern);
|
||||
}
|
||||
$this->addFilterWithExcludedPaths($finder);
|
||||
$filePaths = [];
|
||||
foreach ($finder as $fileInfo) {
|
||||
// getRealPath() function will return false when it checks broken symlinks.
|
||||
// So we should check if this file exists or we got broken symlink
|
||||
/** @var string|false $path */
|
||||
$path = $fileInfo->getRealPath();
|
||||
if ($path !== \false) {
|
||||
$filePaths[] = $path;
|
||||
if ($path === \false) {
|
||||
continue;
|
||||
}
|
||||
if ($this->pathSkipper->shouldSkip($path)) {
|
||||
continue;
|
||||
}
|
||||
$filePaths[] = $path;
|
||||
}
|
||||
return $this->unchangedFilesFilter->filterFileInfos($filePaths);
|
||||
}
|
||||
|
@ -92,49 +96,4 @@ final class FilesFinder
|
|||
$suffixesPattern = \implode('|', $suffixes);
|
||||
return '#\\.(' . $suffixesPattern . ')$#';
|
||||
}
|
||||
private function addFilterWithExcludedPaths(Finder $finder) : void
|
||||
{
|
||||
$excludePaths = $this->skippedPathsResolver->resolve();
|
||||
if ($excludePaths === []) {
|
||||
return;
|
||||
}
|
||||
$finder->filter(function (SplFileInfo $splFileInfo) use($excludePaths) : bool {
|
||||
/** @var string|false $realPath */
|
||||
$realPath = $splFileInfo->getRealPath();
|
||||
if ($realPath === \false) {
|
||||
// dead symlink
|
||||
return \false;
|
||||
}
|
||||
// make the path work accross different OSes
|
||||
$realPath = \str_replace('\\', '/', $realPath);
|
||||
// return false to remove file
|
||||
foreach ($excludePaths as $excludePath) {
|
||||
// make the path work accross different OSes
|
||||
$excludePath = \str_replace('\\', '/', $excludePath);
|
||||
if (\fnmatch($this->normalizeForFnmatch($excludePath), $realPath)) {
|
||||
return \false;
|
||||
}
|
||||
if (\strpos($excludePath, '**') !== \false) {
|
||||
// prevent matching a fnmatch pattern as a regex
|
||||
// which is a waste of resources
|
||||
continue;
|
||||
}
|
||||
if (StringUtils::isMatch($realPath, '#' . \preg_quote($excludePath, '#') . '#')) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* "value*" → "*value*"
|
||||
* "*value" → "*value*"
|
||||
*/
|
||||
private function normalizeForFnmatch(string $path) : string
|
||||
{
|
||||
if (\substr_compare($path, '*', -\strlen('*')) === 0 || \strncmp($path, '*', \strlen('*')) === 0) {
|
||||
return '*' . \trim($path, '*') . '*';
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ final class PathSkipper
|
|||
}
|
||||
public function shouldSkip(string $filePath) : bool
|
||||
{
|
||||
$filePath = \str_replace('\\', '/', $filePath);
|
||||
$skippedPaths = $this->skippedPathsResolver->resolve();
|
||||
return $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user