Updated Rector to commit a6b0d2c732d9532940bce76d45d83d41482c0f5a

a6b0d2c732 [DX] Skip vendor warning in case of downgrade (#5526)
This commit is contained in:
Tomas Votruba 2024-01-30 20:28:41 +00:00
parent e3df11f1c1
commit 89734ded6b
5 changed files with 55 additions and 17 deletions

View File

@ -7,9 +7,9 @@ use RectorPrefix202401\Nette\Utils\FileSystem as UtilsFileSystem;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\VendorMissAnalyseGuard;
use Rector\Parallel\Application\ParallelFileProcessor;
use Rector\Provider\CurrentFileProvider;
use Rector\Skipper\FileSystem\PathNormalizer;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Rector\Util\ArrayParametersMerger;
use Rector\ValueObject\Application\File;
@ -72,6 +72,11 @@ final class ApplicationFileProcessor
* @var \Rector\Util\ArrayParametersMerger
*/
private $arrayParametersMerger;
/**
* @readonly
* @var \Rector\Configuration\VendorMissAnalyseGuard
*/
private $vendorMissAnalyseGuard;
/**
* @var string
*/
@ -80,7 +85,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, VendorMissAnalyseGuard $vendorMissAnalyseGuard)
{
$this->symfonyStyle = $symfonyStyle;
$this->fileFactory = $fileFactory;
@ -91,11 +96,12 @@ final class ApplicationFileProcessor
$this->currentFileProvider = $currentFileProvider;
$this->fileProcessor = $fileProcessor;
$this->arrayParametersMerger = $arrayParametersMerger;
$this->vendorMissAnalyseGuard = $vendorMissAnalyseGuard;
}
public function run(Configuration $configuration, InputInterface $input) : ProcessResult
{
$filePaths = $this->fileFactory->findFilesInPaths($configuration->getPaths(), $configuration);
if ($this->containsVendorPath($filePaths)) {
if ($this->vendorMissAnalyseGuard->isVendorAnalyzed($filePaths)) {
$this->symfonyStyle->warning(\sprintf('Rector is running on your "/vendor" directory. This is not necessary, as Rector access /vendor by composer autoload. It will cause Rector tu run much slower and possibly with errors.%sRemove "/vendor" from Rector paths and run again.', \PHP_EOL . \PHP_EOL));
\sleep(3);
}
@ -245,16 +251,4 @@ final class ApplicationFileProcessor
}
return $potentialRectorBinaryPath;
}
/**
* @param string[] $filePaths
*/
private function containsVendorPath(array $filePaths) : bool
{
foreach ($filePaths as $filePath) {
if (\strpos(PathNormalizer::normalize($filePath), '/vendor/') !== \false) {
return \true;
}
}
return \false;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '0ff8cb0a99db5de31bb999977a5a417bb282e4d2';
public const PACKAGE_VERSION = 'a6b0d2c732d9532940bce76d45d83d41482c0f5a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-30 17:56:03';
public const RELEASE_DATE = '2024-01-30 21:26:19';
/**
* @var int
*/

View File

@ -0,0 +1,42 @@
<?php
declare (strict_types=1);
namespace Rector\Configuration;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Skipper\FileSystem\PathNormalizer;
final class VendorMissAnalyseGuard
{
/**
* @param string[] $filePaths
*/
public function isVendorAnalyzed(array $filePaths) : bool
{
if ($this->hasDowngradeSets()) {
return \false;
}
return $this->containsVendorPath($filePaths);
}
private function hasDowngradeSets() : bool
{
$registeredRectorSets = SimpleParameterProvider::provideArrayParameter(\Rector\Configuration\Option::REGISTERED_RECTOR_SETS);
foreach ($registeredRectorSets as $registeredRectorSet) {
if (\strpos((string) $registeredRectorSet, 'downgrade-') !== \false) {
return \true;
}
}
return \false;
}
/**
* @param string[] $filePaths
*/
private function containsVendorPath(array $filePaths) : bool
{
foreach ($filePaths as $filePath) {
if (\strpos(PathNormalizer::normalize($filePath), '/vendor/') !== \false) {
return \true;
}
}
return \false;
}
}

View File

@ -1178,6 +1178,7 @@ return array(
'Rector\\Configuration\\PhpLevelSetResolver' => $baseDir . '/src/Configuration/PhpLevelSetResolver.php',
'Rector\\Configuration\\RectorConfigBuilder' => $baseDir . '/src/Configuration/RectorConfigBuilder.php',
'Rector\\Configuration\\RenamedClassesDataCollector' => $baseDir . '/src/Configuration/RenamedClassesDataCollector.php',
'Rector\\Configuration\\VendorMissAnalyseGuard' => $baseDir . '/src/Configuration/VendorMissAnalyseGuard.php',
'Rector\\Console\\Command\\CustomRuleCommand' => $baseDir . '/src/Console/Command/CustomRuleCommand.php',
'Rector\\Console\\Command\\ListRulesCommand' => $baseDir . '/src/Console/Command/ListRulesCommand.php',
'Rector\\Console\\Command\\ProcessCommand' => $baseDir . '/src/Console/Command/ProcessCommand.php',

View File

@ -1392,6 +1392,7 @@ class ComposerStaticInitf637847380e2ddf55dcae18dded1d2b3
'Rector\\Configuration\\PhpLevelSetResolver' => __DIR__ . '/../..' . '/src/Configuration/PhpLevelSetResolver.php',
'Rector\\Configuration\\RectorConfigBuilder' => __DIR__ . '/../..' . '/src/Configuration/RectorConfigBuilder.php',
'Rector\\Configuration\\RenamedClassesDataCollector' => __DIR__ . '/../..' . '/src/Configuration/RenamedClassesDataCollector.php',
'Rector\\Configuration\\VendorMissAnalyseGuard' => __DIR__ . '/../..' . '/src/Configuration/VendorMissAnalyseGuard.php',
'Rector\\Console\\Command\\CustomRuleCommand' => __DIR__ . '/../..' . '/src/Console/Command/CustomRuleCommand.php',
'Rector\\Console\\Command\\ListRulesCommand' => __DIR__ . '/../..' . '/src/Console/Command/ListRulesCommand.php',
'Rector\\Console\\Command\\ProcessCommand' => __DIR__ . '/../..' . '/src/Console/Command/ProcessCommand.php',