mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit f68d9f89cece7c081c431ddeeafe2d317514a1cc
f68d9f89ce
[Performance] Extract PathSkipVoter to dedicated service and call before Filesystem::read() (#5451)
This commit is contained in:
parent
5a61fded6a
commit
b68c88f0b4
@ -10,6 +10,7 @@ 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;
|
||||
@ -72,6 +73,11 @@ final class ApplicationFileProcessor
|
||||
* @var \Rector\Util\ArrayParametersMerger
|
||||
*/
|
||||
private $arrayParametersMerger;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Skipper\PathSkipper
|
||||
*/
|
||||
private $pathSkipper;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -80,7 +86,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)
|
||||
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)
|
||||
{
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
$this->fileFactory = $fileFactory;
|
||||
@ -91,6 +97,7 @@ final class ApplicationFileProcessor
|
||||
$this->currentFileProvider = $currentFileProvider;
|
||||
$this->fileProcessor = $fileProcessor;
|
||||
$this->arrayParametersMerger = $arrayParametersMerger;
|
||||
$this->pathSkipper = $pathSkipper;
|
||||
}
|
||||
public function run(Configuration $configuration, InputInterface $input) : ProcessResult
|
||||
{
|
||||
@ -145,6 +152,9 @@ 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 = 'e231caaf0ad81f75b287fb7b2b47f720627a7ca4';
|
||||
public const PACKAGE_VERSION = 'f68d9f89cece7c081c431ddeeafe2d317514a1cc';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-10 16:43:21';
|
||||
public const RELEASE_DATE = '2024-01-10 14:01:07';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -158,7 +158,6 @@ use Rector\Rector\AbstractRector;
|
||||
use Rector\Skipper\Contract\SkipVoterInterface;
|
||||
use Rector\Skipper\Skipper\Skipper;
|
||||
use Rector\Skipper\SkipVoter\ClassSkipVoter;
|
||||
use Rector\Skipper\SkipVoter\PathSkipVoter;
|
||||
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
|
||||
@ -236,7 +235,7 @@ final class LazyContainerFactory
|
||||
/**
|
||||
* @var array<class-string<SkipVoterInterface>>
|
||||
*/
|
||||
private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class, PathSkipVoter::class];
|
||||
private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class];
|
||||
/**
|
||||
* @api used as next rectorConfig factory
|
||||
*/
|
||||
|
@ -18,9 +18,9 @@ final class SkippedPathsResolver
|
||||
*/
|
||||
private $filePathHelper;
|
||||
/**
|
||||
* @var string[]
|
||||
* @var null|string[]
|
||||
*/
|
||||
private $skippedPaths = [];
|
||||
private $skippedPaths = null;
|
||||
public function __construct(FilePathHelper $filePathHelper)
|
||||
{
|
||||
$this->filePathHelper = $filePathHelper;
|
||||
@ -30,15 +30,16 @@ final class SkippedPathsResolver
|
||||
*/
|
||||
public function resolve() : array
|
||||
{
|
||||
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
|
||||
// disable cache in tests
|
||||
$this->skippedPaths = [];
|
||||
}
|
||||
// disable cache in tests
|
||||
if ($this->skippedPaths !== []) {
|
||||
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
|
||||
$this->skippedPaths = null;
|
||||
}
|
||||
// already filled, even empty array
|
||||
if ($this->skippedPaths !== null) {
|
||||
return $this->skippedPaths;
|
||||
}
|
||||
$skip = SimpleParameterProvider::provideArrayParameter(Option::SKIP);
|
||||
$this->skippedPaths = [];
|
||||
foreach ($skip as $key => $value) {
|
||||
if (!\is_int($key)) {
|
||||
continue;
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Skipper\SkipVoter;
|
||||
|
||||
use Rector\Skipper\Contract\SkipVoterInterface;
|
||||
use Rector\Skipper\Matcher\FileInfoMatcher;
|
||||
use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
||||
final class PathSkipVoter implements SkipVoterInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Matcher\FileInfoMatcher
|
||||
*/
|
||||
private $fileInfoMatcher;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver
|
||||
*/
|
||||
private $skippedPathsResolver;
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $skippedFiles = [];
|
||||
public function __construct(FileInfoMatcher $fileInfoMatcher, SkippedPathsResolver $skippedPathsResolver)
|
||||
{
|
||||
$this->fileInfoMatcher = $fileInfoMatcher;
|
||||
$this->skippedPathsResolver = $skippedPathsResolver;
|
||||
}
|
||||
/**
|
||||
* @param string|object $element
|
||||
*/
|
||||
public function match($element) : bool
|
||||
{
|
||||
return \true;
|
||||
}
|
||||
/**
|
||||
* @param string|object $element
|
||||
*/
|
||||
public function shouldSkip($element, string $filePath) : bool
|
||||
{
|
||||
if (isset($this->skippedFiles[$filePath])) {
|
||||
return $this->skippedFiles[$filePath];
|
||||
}
|
||||
$skippedPaths = $this->skippedPathsResolver->resolve();
|
||||
return $this->skippedFiles[$filePath] = $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
|
||||
}
|
||||
}
|
30
src/Skipper/Skipper/PathSkipper.php
Normal file
30
src/Skipper/Skipper/PathSkipper.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Skipper\Skipper;
|
||||
|
||||
use Rector\Skipper\Matcher\FileInfoMatcher;
|
||||
use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
|
||||
final class PathSkipper
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Matcher\FileInfoMatcher
|
||||
*/
|
||||
private $fileInfoMatcher;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver
|
||||
*/
|
||||
private $skippedPathsResolver;
|
||||
public function __construct(FileInfoMatcher $fileInfoMatcher, SkippedPathsResolver $skippedPathsResolver)
|
||||
{
|
||||
$this->fileInfoMatcher = $fileInfoMatcher;
|
||||
$this->skippedPathsResolver = $skippedPathsResolver;
|
||||
}
|
||||
public function shouldSkip(string $filePath) : bool
|
||||
{
|
||||
$skippedPaths = $this->skippedPathsResolver->resolve();
|
||||
return $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
|
||||
}
|
||||
}
|
@ -25,16 +25,18 @@ final class Skipper
|
||||
*/
|
||||
private $skipVoters;
|
||||
/**
|
||||
* @var string
|
||||
* @readonly
|
||||
* @var \Rector\Skipper\Skipper\PathSkipper
|
||||
*/
|
||||
private const FILE_ELEMENT = 'file_elements';
|
||||
private $pathSkipper;
|
||||
/**
|
||||
* @param array<SkipVoterInterface> $skipVoters
|
||||
*/
|
||||
public function __construct(RectifiedAnalyzer $rectifiedAnalyzer, array $skipVoters)
|
||||
public function __construct(RectifiedAnalyzer $rectifiedAnalyzer, array $skipVoters, \Rector\Skipper\Skipper\PathSkipper $pathSkipper)
|
||||
{
|
||||
$this->rectifiedAnalyzer = $rectifiedAnalyzer;
|
||||
$this->skipVoters = $skipVoters;
|
||||
$this->pathSkipper = $pathSkipper;
|
||||
Assert::allIsInstanceOf($this->skipVoters, SkipVoterInterface::class);
|
||||
}
|
||||
/**
|
||||
@ -46,7 +48,7 @@ final class Skipper
|
||||
}
|
||||
public function shouldSkipFilePath(string $filePath) : bool
|
||||
{
|
||||
return $this->shouldSkipElementAndFilePath(self::FILE_ELEMENT, $filePath);
|
||||
return $this->pathSkipper->shouldSkip($filePath);
|
||||
}
|
||||
/**
|
||||
* @param string|object $element
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -2022,7 +2022,7 @@ return array(
|
||||
'Rector\\Skipper\\SkipCriteriaResolver\\SkippedClassResolver' => $baseDir . '/src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php',
|
||||
'Rector\\Skipper\\SkipCriteriaResolver\\SkippedPathsResolver' => $baseDir . '/src/Skipper/SkipCriteriaResolver/SkippedPathsResolver.php',
|
||||
'Rector\\Skipper\\SkipVoter\\ClassSkipVoter' => $baseDir . '/src/Skipper/SkipVoter/ClassSkipVoter.php',
|
||||
'Rector\\Skipper\\SkipVoter\\PathSkipVoter' => $baseDir . '/src/Skipper/SkipVoter/PathSkipVoter.php',
|
||||
'Rector\\Skipper\\Skipper\\PathSkipper' => $baseDir . '/src/Skipper/Skipper/PathSkipper.php',
|
||||
'Rector\\Skipper\\Skipper\\SkipSkipper' => $baseDir . '/src/Skipper/Skipper/SkipSkipper.php',
|
||||
'Rector\\Skipper\\Skipper\\Skipper' => $baseDir . '/src/Skipper/Skipper/Skipper.php',
|
||||
'Rector\\StaticReflection\\DynamicSourceLocatorDecorator' => $baseDir . '/src/StaticReflection/DynamicSourceLocatorDecorator.php',
|
||||
|
2
vendor/composer/autoload_static.php
vendored
2
vendor/composer/autoload_static.php
vendored
@ -2236,7 +2236,7 @@ class ComposerStaticInit09ed4d3982dd982ef2d6920cb3d0f560
|
||||
'Rector\\Skipper\\SkipCriteriaResolver\\SkippedClassResolver' => __DIR__ . '/../..' . '/src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php',
|
||||
'Rector\\Skipper\\SkipCriteriaResolver\\SkippedPathsResolver' => __DIR__ . '/../..' . '/src/Skipper/SkipCriteriaResolver/SkippedPathsResolver.php',
|
||||
'Rector\\Skipper\\SkipVoter\\ClassSkipVoter' => __DIR__ . '/../..' . '/src/Skipper/SkipVoter/ClassSkipVoter.php',
|
||||
'Rector\\Skipper\\SkipVoter\\PathSkipVoter' => __DIR__ . '/../..' . '/src/Skipper/SkipVoter/PathSkipVoter.php',
|
||||
'Rector\\Skipper\\Skipper\\PathSkipper' => __DIR__ . '/../..' . '/src/Skipper/Skipper/PathSkipper.php',
|
||||
'Rector\\Skipper\\Skipper\\SkipSkipper' => __DIR__ . '/../..' . '/src/Skipper/Skipper/SkipSkipper.php',
|
||||
'Rector\\Skipper\\Skipper\\Skipper' => __DIR__ . '/../..' . '/src/Skipper/Skipper/Skipper.php',
|
||||
'Rector\\StaticReflection\\DynamicSourceLocatorDecorator' => __DIR__ . '/../..' . '/src/StaticReflection/DynamicSourceLocatorDecorator.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user