Updated Rector to commit 6e9378e3bf2a4ae78fb53d93e193be473ffcb5d4

6e9378e3bf [DX] Merge RectorOutputStyle, OutputStyleInterface to RectorStyle (#4711)
This commit is contained in:
Tomas Votruba 2023-08-07 21:49:15 +00:00
parent 8689c339f5
commit cd0b3a7cca
21 changed files with 100 additions and 242 deletions

View File

@ -8,7 +8,7 @@ use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Bootstrap\RectorConfigsResolver; use Rector\Core\Bootstrap\RectorConfigsResolver;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Console\ConsoleApplication; use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory; use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\DependencyInjection\RectorContainerFactory; use Rector\Core\DependencyInjection\RectorContainerFactory;
use Rector\Core\Kernel\RectorKernel; use Rector\Core\Kernel\RectorKernel;
use Rector\Core\Util\Reflection\PrivatesAccessor; use Rector\Core\Util\Reflection\PrivatesAccessor;
@ -121,9 +121,9 @@ try {
echo Json::encode(['fatal_errors' => [$throwable->getMessage()]]); echo Json::encode(['fatal_errors' => [$throwable->getMessage()]]);
} else { } else {
// report fatal errors in console format // report fatal errors in console format
$rectorConsoleOutputStyleFactory = new RectorConsoleOutputStyleFactory(new PrivatesAccessor()); $symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor());
$rectorConsoleOutputStyle = $rectorConsoleOutputStyleFactory->create(); $symfonyStyle = $symfonyStyleFactory->create();
$rectorConsoleOutputStyle->error($throwable->getMessage()); $symfonyStyle->error($throwable->getMessage());
} }
exit(Command::FAILURE); exit(Command::FAILURE);
} }

View File

@ -40,8 +40,7 @@ use Rector\Core\Configuration\ConfigInitializer;
use Rector\Core\Console\Command\ListRulesCommand; use Rector\Core\Console\Command\ListRulesCommand;
use Rector\Core\Console\ConsoleApplication; use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Output\OutputFormatterCollector; use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Console\Style\RectorConsoleOutputStyle; use Rector\Core\Console\Style\RectorStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Console\Style\SymfonyStyleFactory; use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\NonPhpRectorInterface; use Rector\Core\Contract\Rector\NonPhpRectorInterface;
@ -137,7 +136,6 @@ return static function (RectorConfig $rectorConfig) : void {
$services->set(BuilderFactory::class); $services->set(BuilderFactory::class);
$services->set(CloningVisitor::class); $services->set(CloningVisitor::class);
$services->set(NodeFinder::class); $services->set(NodeFinder::class);
$services->set(RectorConsoleOutputStyle::class)->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
$services->set(Parser::class)->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']); $services->set(Parser::class)->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']);
$services->set(Lexer::class)->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']); $services->set(Lexer::class)->factory([service(PHPStanServicesFactory::class), 'createEmulativeLexer']);
$services->set(InflectorFactory::class); $services->set(InflectorFactory::class);
@ -145,6 +143,7 @@ return static function (RectorConfig $rectorConfig) : void {
$services->set(VersionParser::class); $services->set(VersionParser::class);
// console // console
$services->set(SymfonyStyleFactory::class); $services->set(SymfonyStyleFactory::class);
$services->alias(RectorStyle::class, SymfonyStyle::class);
$services->set(SymfonyStyle::class)->factory([service(SymfonyStyleFactory::class), 'create']); $services->set(SymfonyStyle::class)->factory([service(SymfonyStyleFactory::class), 'create']);
// cache // cache
$services->set(DependencyResolver::class)->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']); $services->set(DependencyResolver::class)->factory([service(PHPStanServicesFactory::class), 'createDependencyResolver']);

View File

@ -6,18 +6,18 @@ namespace Rector\ChangesReporting\Output;
use RectorPrefix202308\Nette\Utils\Strings; use RectorPrefix202308\Nette\Utils\Strings;
use Rector\ChangesReporting\Annotation\RectorsChangelogResolver; use Rector\ChangesReporting\Annotation\RectorsChangelogResolver;
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface; use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\ValueObject\Configuration; use Rector\Core\ValueObject\Configuration;
use Rector\Core\ValueObject\Error\SystemError; use Rector\Core\ValueObject\Error\SystemError;
use Rector\Core\ValueObject\ProcessResult; use Rector\Core\ValueObject\ProcessResult;
use Rector\Core\ValueObject\Reporting\FileDiff; use Rector\Core\ValueObject\Reporting\FileDiff;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
final class ConsoleOutputFormatter implements OutputFormatterInterface final class ConsoleOutputFormatter implements OutputFormatterInterface
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Core\Contract\Console\OutputStyleInterface * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @readonly * @readonly
* @var \Rector\ChangesReporting\Annotation\RectorsChangelogResolver * @var \Rector\ChangesReporting\Annotation\RectorsChangelogResolver
@ -32,9 +32,9 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
* @see https://regex101.com/r/q8I66g/1 * @see https://regex101.com/r/q8I66g/1
*/ */
private const ON_LINE_REGEX = '# on line #'; private const ON_LINE_REGEX = '# on line #';
public function __construct(OutputStyleInterface $rectorOutputStyle, RectorsChangelogResolver $rectorsChangelogResolver) public function __construct(SymfonyStyle $symfonyStyle, RectorsChangelogResolver $rectorsChangelogResolver)
{ {
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->rectorsChangelogResolver = $rectorsChangelogResolver; $this->rectorsChangelogResolver = $rectorsChangelogResolver;
} }
public function report(ProcessResult $processResult, Configuration $configuration) : void public function report(ProcessResult $processResult, Configuration $configuration) : void
@ -48,10 +48,10 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
} }
// to keep space between progress bar and success message // to keep space between progress bar and success message
if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) { if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) {
$this->rectorOutputStyle->newLine(); $this->symfonyStyle->newLine();
} }
$message = $this->createSuccessMessage($processResult, $configuration); $message = $this->createSuccessMessage($processResult, $configuration);
$this->rectorOutputStyle->success($message); $this->symfonyStyle->success($message);
} }
public function getName() : string public function getName() : string
{ {
@ -68,7 +68,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
// normalize // normalize
\ksort($fileDiffs); \ksort($fileDiffs);
$message = \sprintf('%d file%s with changes', \count($fileDiffs), \count($fileDiffs) === 1 ? '' : 's'); $message = \sprintf('%d file%s with changes', \count($fileDiffs), \count($fileDiffs) === 1 ? '' : 's');
$this->rectorOutputStyle->title($message); $this->symfonyStyle->title($message);
$i = 0; $i = 0;
foreach ($fileDiffs as $fileDiff) { foreach ($fileDiffs as $fileDiff) {
$relativeFilePath = $fileDiff->getRelativeFilePath(); $relativeFilePath = $fileDiff->getRelativeFilePath();
@ -78,14 +78,14 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
$relativeFilePath .= ':' . $firstLineNumber; $relativeFilePath .= ':' . $firstLineNumber;
} }
$message = \sprintf('<options=bold>%d) %s</>', ++$i, $relativeFilePath); $message = \sprintf('<options=bold>%d) %s</>', ++$i, $relativeFilePath);
$this->rectorOutputStyle->writeln($message); $this->symfonyStyle->writeln($message);
$this->rectorOutputStyle->newLine(); $this->symfonyStyle->newLine();
$this->rectorOutputStyle->writeln($fileDiff->getDiffConsoleFormatted()); $this->symfonyStyle->writeln($fileDiff->getDiffConsoleFormatted());
$rectorsChangelogsLines = $this->createRectorChangelogLines($fileDiff); $rectorsChangelogsLines = $this->createRectorChangelogLines($fileDiff);
if ($fileDiff->getRectorChanges() !== []) { if ($fileDiff->getRectorChanges() !== []) {
$this->rectorOutputStyle->writeln('<options=underscore>Applied rules:</>'); $this->symfonyStyle->writeln('<options=underscore>Applied rules:</>');
$this->rectorOutputStyle->listing($rectorsChangelogsLines); $this->symfonyStyle->listing($rectorsChangelogsLines);
$this->rectorOutputStyle->newLine(); $this->symfonyStyle->newLine();
} }
} }
} }
@ -101,7 +101,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
if ($error->getLine() !== null) { if ($error->getLine() !== null) {
$message .= ' On line: ' . $error->getLine(); $message .= ' On line: ' . $error->getLine();
} }
$this->rectorOutputStyle->error($message); $this->symfonyStyle->error($message);
} }
} }
private function normalizePathsToRelativeWithLine(string $errorMessage) : string private function normalizePathsToRelativeWithLine(string $errorMessage) : string

View File

@ -8,7 +8,6 @@ use PHPStan\Analyser\NodeScopeResolver;
use Rector\Caching\Detector\ChangedFilesDetector; use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider; use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Provider\CurrentFileProvider; use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\Util\ArrayParametersMerger; use Rector\Core\Util\ArrayParametersMerger;
@ -21,6 +20,7 @@ use Rector\Parallel\Application\ParallelFileProcessor;
use Rector\Parallel\ValueObject\Bridge; use Rector\Parallel\ValueObject\Bridge;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface; use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix202308\Symplify\EasyParallel\CpuCoreCountProvider; use RectorPrefix202308\Symplify\EasyParallel\CpuCoreCountProvider;
use RectorPrefix202308\Symplify\EasyParallel\Exception\ParallelShouldNotHappenException; use RectorPrefix202308\Symplify\EasyParallel\Exception\ParallelShouldNotHappenException;
use RectorPrefix202308\Symplify\EasyParallel\ScheduleFactory; use RectorPrefix202308\Symplify\EasyParallel\ScheduleFactory;
@ -29,9 +29,9 @@ final class ApplicationFileProcessor
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Core\Contract\Console\OutputStyleInterface * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @readonly * @readonly
* @var \Rector\Core\ValueObjectFactory\Application\FileFactory * @var \Rector\Core\ValueObjectFactory\Application\FileFactory
@ -88,9 +88,9 @@ final class ApplicationFileProcessor
/** /**
* @param FileProcessorInterface[] $fileProcessors * @param FileProcessorInterface[] $fileProcessors
*/ */
public function __construct(OutputStyleInterface $rectorOutputStyle, FileFactory $fileFactory, NodeScopeResolver $nodeScopeResolver, ArrayParametersMerger $arrayParametersMerger, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, iterable $fileProcessors) public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory, NodeScopeResolver $nodeScopeResolver, ArrayParametersMerger $arrayParametersMerger, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, iterable $fileProcessors)
{ {
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->fileFactory = $fileFactory; $this->fileFactory = $fileFactory;
$this->nodeScopeResolver = $nodeScopeResolver; $this->nodeScopeResolver = $nodeScopeResolver;
$this->arrayParametersMerger = $arrayParametersMerger; $this->arrayParametersMerger = $arrayParametersMerger;
@ -133,8 +133,8 @@ final class ApplicationFileProcessor
// progress bar on parallel handled on runParallel() // progress bar on parallel handled on runParallel()
if (!$isParallel && $shouldShowProgressBar) { if (!$isParallel && $shouldShowProgressBar) {
$fileCount = \count($filePaths); $fileCount = \count($filePaths);
$this->rectorOutputStyle->progressStart($fileCount); $this->symfonyStyle->progressStart($fileCount);
$this->rectorOutputStyle->progressAdvance(0); $this->symfonyStyle->progressAdvance(0);
} }
$systemErrorsAndFileDiffs = [Bridge::SYSTEM_ERRORS => [], Bridge::FILE_DIFFS => [], Bridge::SYSTEM_ERRORS_COUNT => 0]; $systemErrorsAndFileDiffs = [Bridge::SYSTEM_ERRORS => [], Bridge::FILE_DIFFS => [], Bridge::SYSTEM_ERRORS_COUNT => 0];
foreach ($filePaths as $filePath) { foreach ($filePaths as $filePath) {
@ -145,7 +145,7 @@ final class ApplicationFileProcessor
// progress bar +1, // progress bar +1,
// progress bar on parallel handled on runParallel() // progress bar on parallel handled on runParallel()
if (!$isParallel && $shouldShowProgressBar) { if (!$isParallel && $shouldShowProgressBar) {
$this->rectorOutputStyle->progressAdvance(); $this->symfonyStyle->progressAdvance();
} }
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
$this->invalidateFile($file); $this->invalidateFile($file);
@ -185,7 +185,7 @@ final class ApplicationFileProcessor
{ {
$errorMessage = \sprintf('System error: "%s"', $throwable->getMessage()) . \PHP_EOL; $errorMessage = \sprintf('System error: "%s"', $throwable->getMessage()) . \PHP_EOL;
$filePath = $filePath instanceof File ? $filePath->getFilePath() : $filePath; $filePath = $filePath instanceof File ? $filePath->getFilePath() : $filePath;
if ($this->rectorOutputStyle->isDebug()) { if ($this->symfonyStyle->isDebug()) {
return new SystemError($errorMessage . \PHP_EOL . 'Stack trace:' . \PHP_EOL . $throwable->getTraceAsString(), $filePath, $throwable->getLine()); return new SystemError($errorMessage . \PHP_EOL . 'Stack trace:' . \PHP_EOL . $throwable->getTraceAsString(), $filePath, $throwable->getLine());
} }
$errorMessage .= 'Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new'; $errorMessage .= 'Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new';
@ -232,10 +232,10 @@ final class ApplicationFileProcessor
}; };
if ($configuration->shouldShowProgressBar()) { if ($configuration->shouldShowProgressBar()) {
$fileCount = \count($filePaths); $fileCount = \count($filePaths);
$this->rectorOutputStyle->progressStart($fileCount); $this->symfonyStyle->progressStart($fileCount);
$this->rectorOutputStyle->progressAdvance(0); $this->symfonyStyle->progressAdvance(0);
$postFileCallback = function (int $stepCount) : void { $postFileCallback = function (int $stepCount) : void {
$this->rectorOutputStyle->progressAdvance($stepCount); $this->symfonyStyle->progressAdvance($stepCount);
// running in parallel here → nothing else to do // running in parallel here → nothing else to do
}; };
} }

View File

@ -9,7 +9,6 @@ use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory; use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory; use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
use Rector\Core\Application\FileProcessor; use Rector\Core\Application\FileProcessor;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\FileSystem\FilePathHelper; use Rector\Core\FileSystem\FilePathHelper;
@ -21,6 +20,7 @@ use Rector\Core\ValueObject\Reporting\FileDiff;
use Rector\Parallel\ValueObject\Bridge; use Rector\Parallel\ValueObject\Bridge;
use Rector\PostRector\Application\PostFileProcessor; use Rector\PostRector\Application\PostFileProcessor;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
use Throwable; use Throwable;
final class PhpFileProcessor implements FileProcessorInterface final class PhpFileProcessor implements FileProcessorInterface
{ {
@ -36,9 +36,9 @@ final class PhpFileProcessor implements FileProcessorInterface
private $fileProcessor; private $fileProcessor;
/** /**
* @readonly * @readonly
* @var \Rector\Core\Contract\Console\OutputStyleInterface * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @readonly * @readonly
* @var \Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory * @var \Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory
@ -69,11 +69,11 @@ final class PhpFileProcessor implements FileProcessorInterface
* @see https://regex101.com/r/xP2MGa/1 * @see https://regex101.com/r/xP2MGa/1
*/ */
private const OPEN_TAG_SPACED_REGEX = '#^(?<open_tag_spaced>[^\\S\\r\\n]+\\<\\?php)#m'; private const OPEN_TAG_SPACED_REGEX = '#^(?<open_tag_spaced>[^\\S\\r\\n]+\\<\\?php)#m';
public function __construct(FormatPerservingPrinter $formatPerservingPrinter, FileProcessor $fileProcessor, OutputStyleInterface $rectorOutputStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, PostFileProcessor $postFileProcessor, ErrorFactory $errorFactory, FilePathHelper $filePathHelper) public function __construct(FormatPerservingPrinter $formatPerservingPrinter, FileProcessor $fileProcessor, SymfonyStyle $symfonyStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, PostFileProcessor $postFileProcessor, ErrorFactory $errorFactory, FilePathHelper $filePathHelper)
{ {
$this->formatPerservingPrinter = $formatPerservingPrinter; $this->formatPerservingPrinter = $formatPerservingPrinter;
$this->fileProcessor = $fileProcessor; $this->fileProcessor = $fileProcessor;
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->fileDiffFactory = $fileDiffFactory; $this->fileDiffFactory = $fileDiffFactory;
$this->changedFilesDetector = $changedFilesDetector; $this->changedFilesDetector = $changedFilesDetector;
$this->postFileProcessor = $postFileProcessor; $this->postFileProcessor = $postFileProcessor;
@ -158,7 +158,7 @@ final class PhpFileProcessor implements FileProcessorInterface
$autoloadSystemError = $this->errorFactory->createAutoloadError($analysedCodeException, $file->getFilePath()); $autoloadSystemError = $this->errorFactory->createAutoloadError($analysedCodeException, $file->getFilePath());
return [$autoloadSystemError]; return [$autoloadSystemError];
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
if ($this->rectorOutputStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) { if ($this->symfonyStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $throwable; throw $throwable;
} }
$relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath()); $relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath());
@ -203,10 +203,10 @@ final class PhpFileProcessor implements FileProcessorInterface
} }
private function notifyFile(File $file) : void private function notifyFile(File $file) : void
{ {
if (!$this->rectorOutputStyle->isVerbose()) { if (!$this->symfonyStyle->isVerbose()) {
return; return;
} }
$relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath()); $relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath());
$this->rectorOutputStyle->writeln($relativeFilePath); $this->symfonyStyle->writeln($relativeFilePath);
} }
} }

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = 'acce9fa86f3942563d11dddf5c37114ee5ae8c00'; public const PACKAGE_VERSION = '6e9378e3bf2a4ae78fb53d93e193be473ffcb5d4';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-08-07 18:34:02'; public const RELEASE_DATE = '2023-08-07 21:45:42';
/** /**
* @var int * @var int
*/ */

View File

@ -5,19 +5,19 @@ namespace Rector\Core\Configuration;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider; use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\ValueObject\Configuration; use Rector\Core\ValueObject\Configuration;
use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface; use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
final class ConfigurationFactory final class ConfigurationFactory
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Core\Contract\Console\OutputStyleInterface * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
public function __construct(OutputStyleInterface $rectorOutputStyle) public function __construct(SymfonyStyle $symfonyStyle)
{ {
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
} }
/** /**
* @api used in tests * @api used in tests
@ -52,7 +52,7 @@ final class ConfigurationFactory
if ($noProgressBar) { if ($noProgressBar) {
return \false; return \false;
} }
if ($this->rectorOutputStyle->isVerbose()) { if ($this->symfonyStyle->isVerbose()) {
return \false; return \false;
} }
return $outputFormat === ConsoleOutputFormatter::NAME; return $outputFormat === ConsoleOutputFormatter::NAME;

View File

@ -6,7 +6,6 @@ namespace Rector\Core\Console\Command;
use RectorPrefix202308\Nette\Utils\Json; use RectorPrefix202308\Nette\Utils\Json;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Console\Output\RectorOutputStyle;
use Rector\Core\Contract\Rector\RectorInterface; use Rector\Core\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface; use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface; use Rector\PostRector\Contract\Rector\PostRectorInterface;
@ -15,14 +14,15 @@ use RectorPrefix202308\Symfony\Component\Console\Command\Command;
use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface; use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202308\Symfony\Component\Console\Input\InputOption; use RectorPrefix202308\Symfony\Component\Console\Input\InputOption;
use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface; use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix202308\Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use RectorPrefix202308\Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
final class ListRulesCommand extends Command final class ListRulesCommand extends Command
{ {
/** /**
* @readonly * @readonly
* @var \Rector\Core\Console\Output\RectorOutputStyle * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @readonly * @readonly
* @var \Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver * @var \Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver
@ -35,9 +35,9 @@ final class ListRulesCommand extends Command
/** /**
* @param RewindableGenerator<RectorInterface>|RectorInterface[] $rectors * @param RewindableGenerator<RectorInterface>|RectorInterface[] $rectors
*/ */
public function __construct(RectorOutputStyle $rectorOutputStyle, SkippedClassResolver $skippedClassResolver, iterable $rectors) public function __construct(SymfonyStyle $symfonyStyle, SkippedClassResolver $skippedClassResolver, iterable $rectors)
{ {
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->skippedClassResolver = $skippedClassResolver; $this->skippedClassResolver = $skippedClassResolver;
parent::__construct(); parent::__construct();
if ($rectors instanceof RewindableGenerator) { if ($rectors instanceof RewindableGenerator) {
@ -61,11 +61,11 @@ final class ListRulesCommand extends Command
echo Json::encode($data, Json::PRETTY) . \PHP_EOL; echo Json::encode($data, Json::PRETTY) . \PHP_EOL;
return Command::SUCCESS; return Command::SUCCESS;
} }
$this->rectorOutputStyle->title('Loaded Rector rules'); $this->symfonyStyle->title('Loaded Rector rules');
$this->rectorOutputStyle->listing($rectorClasses); $this->symfonyStyle->listing($rectorClasses);
if ($skippedClasses !== []) { if ($skippedClasses !== []) {
$this->rectorOutputStyle->title('Skipped Rector rules'); $this->symfonyStyle->title('Skipped Rector rules');
$this->rectorOutputStyle->listing($skippedClasses); $this->symfonyStyle->listing($skippedClasses);
} }
return Command::SUCCESS; return Command::SUCCESS;
} }

View File

@ -11,7 +11,6 @@ use Rector\Core\Configuration\ConfigInitializer;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Console\ExitCode; use Rector\Core\Console\ExitCode;
use Rector\Core\Console\Output\OutputFormatterCollector; use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator; use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Core\Util\MemoryLimiter; use Rector\Core\Util\MemoryLimiter;
@ -21,6 +20,7 @@ use Rector\Core\ValueObjectFactory\ProcessResultFactory;
use RectorPrefix202308\Symfony\Component\Console\Application; use RectorPrefix202308\Symfony\Component\Console\Application;
use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface; use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface; use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessCommand final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessCommand
{ {
/** /**
@ -60,15 +60,15 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
private $outputFormatterCollector; private $outputFormatterCollector;
/** /**
* @readonly * @readonly
* @var \Rector\Core\Contract\Console\OutputStyleInterface * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @readonly * @readonly
* @var \Rector\Core\Util\MemoryLimiter * @var \Rector\Core\Util\MemoryLimiter
*/ */
private $memoryLimiter; private $memoryLimiter;
public function __construct(AdditionalAutoloader $additionalAutoloader, ChangedFilesDetector $changedFilesDetector, ConfigInitializer $configInitializer, ApplicationFileProcessor $applicationFileProcessor, ProcessResultFactory $processResultFactory, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, OutputFormatterCollector $outputFormatterCollector, OutputStyleInterface $rectorOutputStyle, MemoryLimiter $memoryLimiter) public function __construct(AdditionalAutoloader $additionalAutoloader, ChangedFilesDetector $changedFilesDetector, ConfigInitializer $configInitializer, ApplicationFileProcessor $applicationFileProcessor, ProcessResultFactory $processResultFactory, DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, OutputFormatterCollector $outputFormatterCollector, SymfonyStyle $symfonyStyle, MemoryLimiter $memoryLimiter)
{ {
$this->additionalAutoloader = $additionalAutoloader; $this->additionalAutoloader = $additionalAutoloader;
$this->changedFilesDetector = $changedFilesDetector; $this->changedFilesDetector = $changedFilesDetector;
@ -77,7 +77,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
$this->processResultFactory = $processResultFactory; $this->processResultFactory = $processResultFactory;
$this->dynamicSourceLocatorDecorator = $dynamicSourceLocatorDecorator; $this->dynamicSourceLocatorDecorator = $dynamicSourceLocatorDecorator;
$this->outputFormatterCollector = $outputFormatterCollector; $this->outputFormatterCollector = $outputFormatterCollector;
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->memoryLimiter = $memoryLimiter; $this->memoryLimiter = $memoryLimiter;
parent::__construct(); parent::__construct();
} }
@ -98,7 +98,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
$this->memoryLimiter->adjust($configuration); $this->memoryLimiter->adjust($configuration);
// disable console output in case of json output formatter // disable console output in case of json output formatter
if ($configuration->getOutputFormat() === JsonOutputFormatter::NAME) { if ($configuration->getOutputFormat() === JsonOutputFormatter::NAME) {
$this->rectorOutputStyle->setVerbosity(OutputInterface::VERBOSITY_QUIET); $this->symfonyStyle->setVerbosity(OutputInterface::VERBOSITY_QUIET);
} }
$this->additionalAutoloader->autoloadInput($input); $this->additionalAutoloader->autoloadInput($input);
$this->additionalAutoloader->autoloadPaths(); $this->additionalAutoloader->autoloadPaths();
@ -106,7 +106,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
// 1. add files and directories to static locator // 1. add files and directories to static locator
$this->dynamicSourceLocatorDecorator->addPaths($paths); $this->dynamicSourceLocatorDecorator->addPaths($paths);
if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) { if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) {
$this->rectorOutputStyle->error('The given paths do not match any files'); $this->symfonyStyle->error('The given paths do not match any files');
return ExitCode::FAILURE; return ExitCode::FAILURE;
} }
// MAIN PHASE // MAIN PHASE

View File

@ -7,6 +7,7 @@ use RectorPrefix202308\Composer\XdebugHandler\XdebugHandler;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Application\VersionResolver; use Rector\Core\Application\VersionResolver;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use RectorPrefix202308\Symfony\Component\Console\Application; use RectorPrefix202308\Symfony\Component\Console\Application;
use RectorPrefix202308\Symfony\Component\Console\Command\Command; use RectorPrefix202308\Symfony\Component\Console\Command\Command;
use RectorPrefix202308\Symfony\Component\Console\Input\InputDefinition; use RectorPrefix202308\Symfony\Component\Console\Input\InputDefinition;
@ -32,6 +33,13 @@ final class ConsoleApplication extends Application
} }
Assert::allIsInstanceOf($commands, Command::class); Assert::allIsInstanceOf($commands, Command::class);
$this->addCommands($commands); $this->addCommands($commands);
// remove unused commands
$privatesAccessor = new PrivatesAccessor();
$privatesAccessor->propertyClosure($this, 'commands', static function (array $commands) : array {
unset($commands['completion']);
unset($commands['help']);
return $commands;
});
// run this command, if no command name is provided // run this command, if no command name is provided
$this->setDefaultCommand('process'); $this->setDefaultCommand('process');
} }

View File

@ -1,78 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Console\Output;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Contract\Console\OutputStyleInterface;
/**
* This services helps to abstract from Symfony, and allow custom output formatters to use this Rector internal class.
* It is very helpful while scoping Rector from analysed project.
*/
final class RectorOutputStyle implements OutputStyleInterface
{
/**
* @readonly
* @var \Rector\Core\Console\Style\RectorConsoleOutputStyle
*/
private $rectorConsoleOutputStyle;
public function __construct(RectorConsoleOutputStyle $rectorConsoleOutputStyle)
{
$this->rectorConsoleOutputStyle = $rectorConsoleOutputStyle;
}
public function progressStart(int $fileCount) : void
{
$this->rectorConsoleOutputStyle->createProgressBar($fileCount);
}
public function progressAdvance(int $step = 1) : void
{
$this->rectorConsoleOutputStyle->progressAdvance($step);
}
public function error(string $message) : void
{
$this->rectorConsoleOutputStyle->error($message);
}
public function warning(string $message) : void
{
$this->rectorConsoleOutputStyle->warning($message);
}
public function success(string $message) : void
{
$this->rectorConsoleOutputStyle->success($message);
}
public function note(string $message) : void
{
$this->rectorConsoleOutputStyle->note($message);
}
public function title(string $message) : void
{
$this->rectorConsoleOutputStyle->title($message);
}
public function writeln(string $message) : void
{
$this->rectorConsoleOutputStyle->writeln($message);
}
public function newLine(int $count = 1) : void
{
$this->rectorConsoleOutputStyle->newLine($count);
}
/**
* @param string[] $elements
*/
public function listing(array $elements) : void
{
$this->rectorConsoleOutputStyle->listing($elements);
}
public function isVerbose() : bool
{
return $this->rectorConsoleOutputStyle->isVerbose();
}
public function isDebug() : bool
{
return $this->rectorConsoleOutputStyle->isDebug();
}
public function setVerbosity(int $level) : void
{
$this->rectorConsoleOutputStyle->setVerbosity($level);
}
}

View File

@ -1,34 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Console\Style;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use RectorPrefix202308\Symfony\Component\Console\Application;
use RectorPrefix202308\Symfony\Component\Console\Input\ArgvInput;
use RectorPrefix202308\Symfony\Component\Console\Output\ConsoleOutput;
use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface;
final class RectorConsoleOutputStyleFactory
{
/**
* @readonly
* @var \Rector\Core\Util\Reflection\PrivatesAccessor
*/
private $privatesAccessor;
public function __construct(PrivatesAccessor $privatesAccessor)
{
$this->privatesAccessor = $privatesAccessor;
}
public function create() : \Rector\Core\Console\Style\RectorConsoleOutputStyle
{
$argvInput = new ArgvInput();
$consoleOutput = new ConsoleOutput();
// to configure all -v, -vv, -vvv options without memory-lock to Application run() arguments
$this->privatesAccessor->callPrivateMethod(new Application(), 'configureIO', [$argvInput, $consoleOutput]);
// --debug is called
if ($argvInput->hasParameterOption('--debug')) {
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
}
return new \Rector\Core\Console\Style\RectorConsoleOutputStyle($argvInput, $consoleOutput);
}
}

View File

@ -9,7 +9,7 @@ use RectorPrefix202308\Symfony\Component\Console\Helper\ProgressBar;
use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface; use RectorPrefix202308\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface; use RectorPrefix202308\Symfony\Component\Console\Output\OutputInterface;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle; use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
final class RectorConsoleOutputStyle extends SymfonyStyle final class RectorStyle extends SymfonyStyle
{ {
/** /**
* @var \Symfony\Component\Console\Helper\ProgressBar|null * @var \Symfony\Component\Console\Helper\ProgressBar|null

View File

@ -41,7 +41,7 @@ final class SymfonyStyleFactory
if ($this->isPHPUnitRun()) { if ($this->isPHPUnitRun()) {
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_QUIET); $consoleOutput->setVerbosity(OutputInterface::VERBOSITY_QUIET);
} }
return new SymfonyStyle($argvInput, $consoleOutput); return new \Rector\Core\Console\Style\RectorStyle($argvInput, $consoleOutput);
} }
/** /**
* Never ever used static methods if not neccesary, this is just handy for tests + src to prevent duplication. * Never ever used static methods if not neccesary, this is just handy for tests + src to prevent duplication.

View File

@ -1,24 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Contract\Console;
interface OutputStyleInterface
{
public function error(string $message) : void;
public function success(string $message) : void;
public function warning(string $message) : void;
public function note(string $message) : void;
public function title(string $message) : void;
public function writeln(string $message) : void;
public function newLine(int $count = 1) : void;
/**
* @param string[] $elements
*/
public function listing(array $elements) : void;
public function isVerbose() : bool;
public function isDebug() : bool;
public function setVerbosity(int $level) : void;
public function progressStart(int $fileCount) : void;
public function progressAdvance(int $step = 1) : void;
}

View File

@ -42,11 +42,8 @@ use Rector\Core\Application\FileProcessor\PhpFileProcessor;
use Rector\Core\Configuration\ConfigInitializer; use Rector\Core\Configuration\ConfigInitializer;
use Rector\Core\Configuration\CurrentNodeProvider; use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Console\Output\OutputFormatterCollector; use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Console\Output\RectorOutputStyle; use Rector\Core\Console\Style\RectorStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Console\Style\SymfonyStyleFactory; use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\NonPhpRectorInterface; use Rector\Core\Contract\Rector\NonPhpRectorInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface; use Rector\Core\Contract\Rector\PhpRectorInterface;
@ -258,7 +255,6 @@ final class LazyContainerFactory
$inflectorFactory = new InflectorFactory(); $inflectorFactory = new InflectorFactory();
return $inflectorFactory->build(); return $inflectorFactory->build();
}); });
$lazyRectorConfig->singleton(OutputStyleInterface::class, RectorOutputStyle::class);
$lazyRectorConfig->singleton(PhpFileProcessor::class); $lazyRectorConfig->singleton(PhpFileProcessor::class);
$lazyRectorConfig->tag(PhpFileProcessor::class, FileProcessorInterface::class); $lazyRectorConfig->tag(PhpFileProcessor::class, FileProcessorInterface::class);
$lazyRectorConfig->singleton(NonPhpFileProcessor::class); $lazyRectorConfig->singleton(NonPhpFileProcessor::class);
@ -268,10 +264,6 @@ final class LazyContainerFactory
$lazyRectorConfig->when(FileFactory::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class); $lazyRectorConfig->when(FileFactory::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class);
$lazyRectorConfig->when(RectorNodeTraverser::class)->needs('$phpRectors')->giveTagged(PhpRectorInterface::class); $lazyRectorConfig->when(RectorNodeTraverser::class)->needs('$phpRectors')->giveTagged(PhpRectorInterface::class);
$lazyRectorConfig->when(ConfigInitializer::class)->needs('$rectors')->giveTagged(RectorInterface::class); $lazyRectorConfig->when(ConfigInitializer::class)->needs('$rectors')->giveTagged(RectorInterface::class);
$lazyRectorConfig->singleton(RectorConsoleOutputStyle::class, static function (Container $container) : RectorConsoleOutputStyle {
$rectorConsoleOutputStyleFactory = $container->make(RectorConsoleOutputStyleFactory::class);
return $rectorConsoleOutputStyleFactory->create();
});
$lazyRectorConfig->when(ClassNameImportSkipper::class)->needs('$classNameImportSkipVoters')->giveTagged(ClassNameImportSkipVoterInterface::class); $lazyRectorConfig->when(ClassNameImportSkipper::class)->needs('$classNameImportSkipVoters')->giveTagged(ClassNameImportSkipVoterInterface::class);
$lazyRectorConfig->singleton(DynamicSourceLocatorProvider::class, static function (Container $container) : DynamicSourceLocatorProvider { $lazyRectorConfig->singleton(DynamicSourceLocatorProvider::class, static function (Container $container) : DynamicSourceLocatorProvider {
$phpStanServicesFactory = $container->make(PHPStanServicesFactory::class); $phpStanServicesFactory = $container->make(PHPStanServicesFactory::class);
@ -292,7 +284,7 @@ final class LazyContainerFactory
// node name resolvers // node name resolvers
$lazyRectorConfig->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class); $lazyRectorConfig->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class);
$lazyRectorConfig->afterResolving(AbstractRector::class, static function (AbstractRector $rector, Container $container) : void { $lazyRectorConfig->afterResolving(AbstractRector::class, static function (AbstractRector $rector, Container $container) : void {
$rector->autowire($container->make(NodeNameResolver::class), $container->make(NodeTypeResolver::class), $container->make(SimpleCallableNodeTraverser::class), $container->make(NodeFactory::class), $container->make(PhpDocInfoFactory::class), $container->make(StaticTypeMapper::class), $container->make(CurrentRectorProvider::class), $container->make(CurrentNodeProvider::class), $container->make(Skipper::class), $container->make(ValueResolver::class), $container->make(BetterNodeFinder::class), $container->make(NodeComparator::class), $container->make(CurrentFileProvider::class), $container->make(RectifiedAnalyzer::class), $container->make(CreatedByRuleDecorator::class), $container->make(ChangedNodeScopeRefresher::class), $container->make(RectorOutputStyle::class), $container->make(FilePathHelper::class)); $rector->autowire($container->make(NodeNameResolver::class), $container->make(NodeTypeResolver::class), $container->make(SimpleCallableNodeTraverser::class), $container->make(NodeFactory::class), $container->make(PhpDocInfoFactory::class), $container->make(StaticTypeMapper::class), $container->make(CurrentRectorProvider::class), $container->make(CurrentNodeProvider::class), $container->make(Skipper::class), $container->make(ValueResolver::class), $container->make(BetterNodeFinder::class), $container->make(NodeComparator::class), $container->make(CurrentFileProvider::class), $container->make(RectifiedAnalyzer::class), $container->make(CreatedByRuleDecorator::class), $container->make(ChangedNodeScopeRefresher::class), $container->make(RectorStyle::class), $container->make(FilePathHelper::class));
}); });
$this->registerTagged($lazyRectorConfig, self::PHP_PARSER_NODE_MAPPER_CLASSES, PhpParserNodeMapperInterface::class); $this->registerTagged($lazyRectorConfig, self::PHP_PARSER_NODE_MAPPER_CLASSES, PhpParserNodeMapperInterface::class);
$this->registerTagged($lazyRectorConfig, self::PHP_DOC_NODE_DECORATOR_CLASSES, PhpDocNodeDecoratorInterface::class); $this->registerTagged($lazyRectorConfig, self::PHP_DOC_NODE_DECORATOR_CLASSES, PhpDocNodeDecoratorInterface::class);
@ -302,6 +294,7 @@ final class LazyContainerFactory
$this->registerTagged($lazyRectorConfig, self::NODE_TYPE_RESOLVER_CLASSES, NodeTypeResolverInterface::class); $this->registerTagged($lazyRectorConfig, self::NODE_TYPE_RESOLVER_CLASSES, NodeTypeResolverInterface::class);
$this->registerTagged($lazyRectorConfig, self::OUTPUT_FORMATTER_CLASSES, OutputFormatterInterface::class); $this->registerTagged($lazyRectorConfig, self::OUTPUT_FORMATTER_CLASSES, OutputFormatterInterface::class);
$this->registerTagged($lazyRectorConfig, self::CLASS_NAME_IMPORT_SKIPPER_CLASSES, ClassNameImportSkipVoterInterface::class); $this->registerTagged($lazyRectorConfig, self::CLASS_NAME_IMPORT_SKIPPER_CLASSES, ClassNameImportSkipVoterInterface::class);
$lazyRectorConfig->alias(RectorStyle::class, SymfonyStyle::class);
$lazyRectorConfig->singleton(SymfonyStyle::class, static function (Container $container) : SymfonyStyle { $lazyRectorConfig->singleton(SymfonyStyle::class, static function (Container $container) : SymfonyStyle {
$symfonyStyleFactory = $container->make(SymfonyStyleFactory::class); $symfonyStyleFactory = $container->make(SymfonyStyleFactory::class);
return $symfonyStyleFactory->create(); return $symfonyStyleFactory->create();

View File

@ -18,7 +18,6 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange; use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Application\ChangedNodeScopeRefresher; use Rector\Core\Application\ChangedNodeScopeRefresher;
use Rector\Core\Configuration\CurrentNodeProvider; use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Console\Output\RectorOutputStyle;
use Rector\Core\Contract\Rector\PhpRectorInterface; use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\FileSystem\FilePathHelper; use Rector\Core\FileSystem\FilePathHelper;
@ -37,6 +36,7 @@ use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\Skipper\Skipper\Skipper; use Rector\Skipper\Skipper\Skipper;
use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\StaticTypeMapper;
use RectorPrefix202308\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix202308\Symfony\Contracts\Service\Attribute\Required; use RectorPrefix202308\Symfony\Contracts\Service\Attribute\Required;
abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorInterface abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorInterface
{ {
@ -131,9 +131,9 @@ CODE_SAMPLE;
*/ */
private $createdByRuleDecorator; private $createdByRuleDecorator;
/** /**
* @var \Rector\Core\Console\Output\RectorOutputStyle * @var \Symfony\Component\Console\Style\SymfonyStyle
*/ */
private $rectorOutputStyle; private $symfonyStyle;
/** /**
* @var \Rector\Core\FileSystem\FilePathHelper * @var \Rector\Core\FileSystem\FilePathHelper
*/ */
@ -145,7 +145,7 @@ CODE_SAMPLE;
/** /**
* @required * @required
*/ */
public function autowire(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, CurrentRectorProvider $currentRectorProvider, CurrentNodeProvider $currentNodeProvider, Skipper $skipper, ValueResolver $valueResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, RectifiedAnalyzer $rectifiedAnalyzer, CreatedByRuleDecorator $createdByRuleDecorator, ChangedNodeScopeRefresher $changedNodeScopeRefresher, RectorOutputStyle $rectorOutputStyle, FilePathHelper $filePathHelper) : void public function autowire(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, CurrentRectorProvider $currentRectorProvider, CurrentNodeProvider $currentNodeProvider, Skipper $skipper, ValueResolver $valueResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, CurrentFileProvider $currentFileProvider, RectifiedAnalyzer $rectifiedAnalyzer, CreatedByRuleDecorator $createdByRuleDecorator, ChangedNodeScopeRefresher $changedNodeScopeRefresher, SymfonyStyle $symfonyStyle, FilePathHelper $filePathHelper) : void
{ {
$this->nodeNameResolver = $nodeNameResolver; $this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver; $this->nodeTypeResolver = $nodeTypeResolver;
@ -163,7 +163,7 @@ CODE_SAMPLE;
$this->rectifiedAnalyzer = $rectifiedAnalyzer; $this->rectifiedAnalyzer = $rectifiedAnalyzer;
$this->createdByRuleDecorator = $createdByRuleDecorator; $this->createdByRuleDecorator = $createdByRuleDecorator;
$this->changedNodeScopeRefresher = $changedNodeScopeRefresher; $this->changedNodeScopeRefresher = $changedNodeScopeRefresher;
$this->rectorOutputStyle = $rectorOutputStyle; $this->symfonyStyle = $symfonyStyle;
$this->filePathHelper = $filePathHelper; $this->filePathHelper = $filePathHelper;
} }
/** /**
@ -187,7 +187,7 @@ CODE_SAMPLE;
if ($this->shouldSkipCurrentNode($node)) { if ($this->shouldSkipCurrentNode($node)) {
return null; return null;
} }
$isDebug = $this->rectorOutputStyle->isDebug(); $isDebug = $this->symfonyStyle->isDebug();
$this->currentRectorProvider->changeCurrentRector($this); $this->currentRectorProvider->changeCurrentRector($this);
// for PHP doc info factory and change notifier // for PHP doc info factory and change notifier
$this->currentNodeProvider->setNode($node); $this->currentNodeProvider->setNode($node);
@ -363,15 +363,15 @@ CODE_SAMPLE;
private function printCurrentFileAndRule() : void private function printCurrentFileAndRule() : void
{ {
$relativeFilePath = $this->filePathHelper->relativePath($this->file->getFilePath()); $relativeFilePath = $this->filePathHelper->relativePath($this->file->getFilePath());
$this->rectorOutputStyle->writeln('[file] ' . $relativeFilePath); $this->symfonyStyle->writeln('[file] ' . $relativeFilePath);
$this->rectorOutputStyle->writeln('[rule] ' . static::class); $this->symfonyStyle->writeln('[rule] ' . static::class);
} }
private function printConsumptions(float $startTime, int $previousMemory) : void private function printConsumptions(float $startTime, int $previousMemory) : void
{ {
$elapsedTime = \microtime(\true) - $startTime; $elapsedTime = \microtime(\true) - $startTime;
$currentTotalMemory = \memory_get_peak_usage(\true); $currentTotalMemory = \memory_get_peak_usage(\true);
$consumed = \sprintf('--- consumed %s, total %s, took %.2f s', BytesHelper::bytes($currentTotalMemory - $previousMemory), BytesHelper::bytes($currentTotalMemory), $elapsedTime); $consumed = \sprintf('--- consumed %s, total %s, took %.2f s', BytesHelper::bytes($currentTotalMemory - $previousMemory), BytesHelper::bytes($currentTotalMemory), $elapsedTime);
$this->rectorOutputStyle->writeln($consumed); $this->symfonyStyle->writeln($consumed);
$this->rectorOutputStyle->newLine(1); $this->symfonyStyle->newLine(1);
} }
} }

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit1ab3abf084614a2564c15cafc53d154f::getLoader(); return ComposerAutoloaderInit2de9e0e7fdbb90e14135faecd56343a6::getLoader();

View File

@ -1520,11 +1520,8 @@ return array(
'Rector\\Core\\Console\\Formatter\\CompleteUnifiedDiffOutputBuilderFactory' => $baseDir . '/src/Console/Formatter/CompleteUnifiedDiffOutputBuilderFactory.php', 'Rector\\Core\\Console\\Formatter\\CompleteUnifiedDiffOutputBuilderFactory' => $baseDir . '/src/Console/Formatter/CompleteUnifiedDiffOutputBuilderFactory.php',
'Rector\\Core\\Console\\Formatter\\ConsoleDiffer' => $baseDir . '/src/Console/Formatter/ConsoleDiffer.php', 'Rector\\Core\\Console\\Formatter\\ConsoleDiffer' => $baseDir . '/src/Console/Formatter/ConsoleDiffer.php',
'Rector\\Core\\Console\\Output\\OutputFormatterCollector' => $baseDir . '/src/Console/Output/OutputFormatterCollector.php', 'Rector\\Core\\Console\\Output\\OutputFormatterCollector' => $baseDir . '/src/Console/Output/OutputFormatterCollector.php',
'Rector\\Core\\Console\\Output\\RectorOutputStyle' => $baseDir . '/src/Console/Output/RectorOutputStyle.php', 'Rector\\Core\\Console\\Style\\RectorStyle' => $baseDir . '/src/Console/Style/RectorStyle.php',
'Rector\\Core\\Console\\Style\\RectorConsoleOutputStyle' => $baseDir . '/src/Console/Style/RectorConsoleOutputStyle.php',
'Rector\\Core\\Console\\Style\\RectorConsoleOutputStyleFactory' => $baseDir . '/src/Console/Style/RectorConsoleOutputStyleFactory.php',
'Rector\\Core\\Console\\Style\\SymfonyStyleFactory' => $baseDir . '/src/Console/Style/SymfonyStyleFactory.php', 'Rector\\Core\\Console\\Style\\SymfonyStyleFactory' => $baseDir . '/src/Console/Style/SymfonyStyleFactory.php',
'Rector\\Core\\Contract\\Console\\OutputStyleInterface' => $baseDir . '/src/Contract/Console/OutputStyleInterface.php',
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => $baseDir . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php', 'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => $baseDir . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => $baseDir . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php', 'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => $baseDir . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => $baseDir . '/src/Contract/Processor/FileProcessorInterface.php', 'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => $baseDir . '/src/Contract/Processor/FileProcessorInterface.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit1ab3abf084614a2564c15cafc53d154f class ComposerAutoloaderInit2de9e0e7fdbb90e14135faecd56343a6
{ {
private static $loader; private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1ab3abf084614a2564c15cafc53d154f
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit1ab3abf084614a2564c15cafc53d154f', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit2de9e0e7fdbb90e14135faecd56343a6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit1ab3abf084614a2564c15cafc53d154f', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit2de9e0e7fdbb90e14135faecd56343a6', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit1ab3abf084614a2564c15cafc53d154f::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6::getInitializer($loader));
$loader->setClassMapAuthoritative(true); $loader->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit1ab3abf084614a2564c15cafc53d154f::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit1ab3abf084614a2564c15cafc53d154f class ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1774,11 +1774,8 @@ class ComposerStaticInit1ab3abf084614a2564c15cafc53d154f
'Rector\\Core\\Console\\Formatter\\CompleteUnifiedDiffOutputBuilderFactory' => __DIR__ . '/../..' . '/src/Console/Formatter/CompleteUnifiedDiffOutputBuilderFactory.php', 'Rector\\Core\\Console\\Formatter\\CompleteUnifiedDiffOutputBuilderFactory' => __DIR__ . '/../..' . '/src/Console/Formatter/CompleteUnifiedDiffOutputBuilderFactory.php',
'Rector\\Core\\Console\\Formatter\\ConsoleDiffer' => __DIR__ . '/../..' . '/src/Console/Formatter/ConsoleDiffer.php', 'Rector\\Core\\Console\\Formatter\\ConsoleDiffer' => __DIR__ . '/../..' . '/src/Console/Formatter/ConsoleDiffer.php',
'Rector\\Core\\Console\\Output\\OutputFormatterCollector' => __DIR__ . '/../..' . '/src/Console/Output/OutputFormatterCollector.php', 'Rector\\Core\\Console\\Output\\OutputFormatterCollector' => __DIR__ . '/../..' . '/src/Console/Output/OutputFormatterCollector.php',
'Rector\\Core\\Console\\Output\\RectorOutputStyle' => __DIR__ . '/../..' . '/src/Console/Output/RectorOutputStyle.php', 'Rector\\Core\\Console\\Style\\RectorStyle' => __DIR__ . '/../..' . '/src/Console/Style/RectorStyle.php',
'Rector\\Core\\Console\\Style\\RectorConsoleOutputStyle' => __DIR__ . '/../..' . '/src/Console/Style/RectorConsoleOutputStyle.php',
'Rector\\Core\\Console\\Style\\RectorConsoleOutputStyleFactory' => __DIR__ . '/../..' . '/src/Console/Style/RectorConsoleOutputStyleFactory.php',
'Rector\\Core\\Console\\Style\\SymfonyStyleFactory' => __DIR__ . '/../..' . '/src/Console/Style/SymfonyStyleFactory.php', 'Rector\\Core\\Console\\Style\\SymfonyStyleFactory' => __DIR__ . '/../..' . '/src/Console/Style/SymfonyStyleFactory.php',
'Rector\\Core\\Contract\\Console\\OutputStyleInterface' => __DIR__ . '/../..' . '/src/Contract/Console/OutputStyleInterface.php',
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => __DIR__ . '/../..' . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php', 'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => __DIR__ . '/../..' . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => __DIR__ . '/../..' . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php', 'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => __DIR__ . '/../..' . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => __DIR__ . '/../..' . '/src/Contract/Processor/FileProcessorInterface.php', 'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => __DIR__ . '/../..' . '/src/Contract/Processor/FileProcessorInterface.php',
@ -3012,9 +3009,9 @@ class ComposerStaticInit1ab3abf084614a2564c15cafc53d154f
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit1ab3abf084614a2564c15cafc53d154f::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1ab3abf084614a2564c15cafc53d154f::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1ab3abf084614a2564c15cafc53d154f::$classMap; $loader->classMap = ComposerStaticInit2de9e0e7fdbb90e14135faecd56343a6::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }