Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\Style\RectorStyle;
use Rector\FileSystem\FilesFinder;
use Rector\Parallel\Application\ParallelFileProcessor;
use Rector\Parallel\CpuCoreCountProvider;
Expand All @@ -27,7 +28,6 @@
use Rector\ValueObject\ProcessResult;
use Rector\ValueObject\Reporting\FileDiff;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

final class ApplicationFileProcessor
Expand All @@ -40,7 +40,7 @@ final class ApplicationFileProcessor
private array $systemErrors = [];

public function __construct(
private readonly SymfonyStyle $symfonyStyle,
private readonly RectorStyle $rectorStyle,
private readonly FilesFinder $filesFinder,
private readonly ParallelFileProcessor $parallelFileProcessor,
private readonly ScheduleFactory $scheduleFactory,
Expand Down Expand Up @@ -76,11 +76,11 @@ public function run(Configuration $configuration, InputInterface $input): Proces
*/
if ($configuration->shouldShowProgressBar()) {
$fileCount = count($filePaths);
$this->symfonyStyle->progressStart($fileCount);
$this->symfonyStyle->progressAdvance(0);
$this->rectorStyle->progressStart($fileCount);
$this->rectorStyle->progressAdvance(0);

$postFileCallback = function (int $stepCount): void {
$this->symfonyStyle->progressAdvance($stepCount);
$this->rectorStyle->progressAdvance($stepCount);
// running in parallel here → nothing else to do
};
} else {
Expand All @@ -90,7 +90,7 @@ public function run(Configuration $configuration, InputInterface $input): Proces

if ($configuration->isDebug()) {
$preFileCallback = function (string $filePath): void {
$this->symfonyStyle->writeln('[file] ' . $filePath);
$this->rectorStyle->writeln('[file] ' . $filePath);
};
} else {
$preFileCallback = null;
Expand Down Expand Up @@ -212,7 +212,7 @@ private function resolveSystemError(Throwable $throwable, string $filePath): Sys
{
$errorMessage = sprintf('System error: "%s"', $throwable->getMessage()) . PHP_EOL;

if ($this->symfonyStyle->isDebug()) {
if ($this->rectorStyle->isDebug()) {
$errorMessage .= PHP_EOL . 'Stack trace:' . PHP_EOL . $throwable->getTraceAsString();
} else {
$errorMessage .= 'Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new';
Expand Down
6 changes: 3 additions & 3 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
use Rector\CodingStyle\ClassNameImport\UsedImportsResolver;
use Rector\Console\Style\RectorStyle;
use Rector\Exception\ShouldNotHappenException;
use Rector\FileSystem\FilePathHelper;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
Expand All @@ -27,15 +28,14 @@
use Rector\ValueObject\Configuration;
use Rector\ValueObject\Error\SystemError;
use Rector\ValueObject\FileProcessResult;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

final readonly class FileProcessor
{
public function __construct(
private BetterStandardPrinter $betterStandardPrinter,
private RectorNodeTraverser $rectorNodeTraverser,
private SymfonyStyle $symfonyStyle,
private RectorStyle $rectorStyle,
private FileDiffFactory $fileDiffFactory,
private ChangedFilesDetector $changedFilesDetector,
private ErrorFactory $errorFactory,
Expand Down Expand Up @@ -151,7 +151,7 @@ private function parseFileAndDecorateNodes(File $file): ?SystemError

return $this->errorFactory->createAutoloadError($analysedCodeException, $file->getFilePath());
} catch (Throwable $throwable) {
if ($this->symfonyStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
if ($this->rectorStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $throwable;
}

Expand Down
30 changes: 15 additions & 15 deletions src/ChangesReporting/Output/ConsoleOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\Style\RectorStyle;
use Rector\ValueObject\Configuration;
use Rector\ValueObject\Error\SystemError;
use Rector\ValueObject\ProcessResult;
use Rector\ValueObject\Reporting\FileDiff;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class ConsoleOutputFormatter implements OutputFormatterInterface
{
Expand All @@ -25,7 +25,7 @@
private const string ON_LINE_REGEX = '# on line #';

public function __construct(
private SymfonyStyle $symfonyStyle,
private RectorStyle $rectorStyle,
) {
}

Expand All @@ -43,15 +43,15 @@ public function report(ProcessResult $processResult, Configuration $configuratio

// to keep space between progress bar and success message
if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) {
$this->symfonyStyle->newLine();
$this->rectorStyle->newLine();
}

if ($configuration->shouldShowRulesSummary()) {
$this->reportRulesSummary($processResult, $configuration);
}

$message = $this->createSuccessMessage($processResult, $configuration);
$this->symfonyStyle->success($message);
$this->rectorStyle->success($message);
}

public function getName(): string
Expand All @@ -72,7 +72,7 @@ private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath): void
ksort($fileDiffs);
$message = sprintf('%d file%s with changes', count($fileDiffs), count($fileDiffs) === 1 ? '' : 's');

$this->symfonyStyle->title($message);
$this->rectorStyle->title($message);

$i = 0;
foreach ($fileDiffs as $fileDiff) {
Expand All @@ -95,14 +95,14 @@ private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath): void

$message = sprintf('<options=bold>%d) %s</>', ++$i, $filePathWithUrl);

$this->symfonyStyle->writeln($message);
$this->symfonyStyle->newLine();
$this->symfonyStyle->writeln($fileDiff->getDiffConsoleFormatted());
$this->rectorStyle->writeln($message);
$this->rectorStyle->newLine();
$this->rectorStyle->writeln($fileDiff->getDiffConsoleFormatted());

if ($fileDiff->getRectorChanges() !== []) {
$this->symfonyStyle->writeln('<options=underscore>Applied rules:</>');
$this->symfonyStyle->listing($fileDiff->getRectorShortClasses());
$this->symfonyStyle->newLine();
$this->rectorStyle->writeln('<options=underscore>Applied rules:</>');
$this->rectorStyle->listing($fileDiff->getRectorShortClasses());
$this->rectorStyle->newLine();
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ private function reportErrors(array $errors, bool $absoluteFilePath): void
$message .= ' On line: ' . $error->getLine();
}

$this->symfonyStyle->error($message);
$this->rectorStyle->error($message);
}
}

Expand All @@ -144,11 +144,11 @@ private function reportRulesSummary(ProcessResult $processResult, Configuration

$verb = $configuration->isDryRun() ? 'would have been applied' : 'was applied';

$this->symfonyStyle->section('Rules Summary');
$this->rectorStyle->section('Rules Summary');

foreach ($ruleApplicationCounts as $ruleClass => $count) {
$ruleShortClass = (string) Strings::after($ruleClass, '\\', -1);
$this->symfonyStyle->writeln(sprintf(
$this->rectorStyle->writeln(sprintf(
' * <info>%s</info> %s <comment>%d</comment> time%s',
$ruleShortClass,
$verb,
Expand All @@ -157,7 +157,7 @@ private function reportRulesSummary(ProcessResult $processResult, Configuration
));
}

$this->symfonyStyle->newLine();
$this->rectorStyle->newLine();
}

private function normalizePathsToRelativeWithLine(string $errorMessage): string
Expand Down
16 changes: 8 additions & 8 deletions src/Configuration/ConfigInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Nette\Utils\FileSystem;
use Rector\Agentic\TerminalDetector;
use Rector\Bootstrap\RectorConfigsResolver;
use Rector\Console\Style\RectorStyle;
use Rector\Contract\Rector\RectorInterface;
use Rector\FileSystem\InitFilePathsResolver;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class ConfigInitializer
{
Expand All @@ -20,7 +20,7 @@
public function __construct(
private array $rectors,
private InitFilePathsResolver $initFilePathsResolver,
private SymfonyStyle $symfonyStyle,
private RectorStyle $rectorStyle,
private RectorConfigsResolver $rectorConfigsResolver,
) {
}
Expand All @@ -31,14 +31,14 @@ public function createConfig(string $projectDirectory): void
$distRectorConfigPath = $projectDirectory . '/' . RectorConfigsResolver::DEFAULT_DIST_CONFIG_FILE;

if (file_exists($commonRectorConfigPath)) {
$this->symfonyStyle->warning(
$this->rectorStyle->warning(
'Register rules or sets in your "' . RectorConfigsResolver::DEFAULT_CONFIG_FILE . '" config'
);
return;
}

if (file_exists($distRectorConfigPath)) {
$this->symfonyStyle->warning(
$this->rectorStyle->warning(
'Register rules or sets in your "' . RectorConfigsResolver::DEFAULT_DIST_CONFIG_FILE . '" config'
);
return;
Expand All @@ -47,7 +47,7 @@ public function createConfig(string $projectDirectory): void
$mainConfigFile = $this->rectorConfigsResolver->provide()
->getMainConfigFile();
if ($mainConfigFile !== null && file_exists($mainConfigFile)) {
$this->symfonyStyle->warning(
$this->rectorStyle->warning(
'Register rules or sets in your "' . basename($mainConfigFile) . '" config'
);
return;
Expand All @@ -56,14 +56,14 @@ public function createConfig(string $projectDirectory): void
// non-interactive terminal, e.g. piped output, CI or an agent: never prompt or silently write a
// config, just say what to do - Symfony still treats a closed STDIN as interactive here
if (! TerminalDetector::isInputTty()) {
$this->symfonyStyle->warning(sprintf(
$this->rectorStyle->warning(sprintf(
'No "%s" config found. Create one, or pass "--config <path>".',
RectorConfigsResolver::DEFAULT_CONFIG_FILE
));
return;
}

$response = $this->symfonyStyle->ask(
$response = $this->rectorStyle->ask(
'No "' . RectorConfigsResolver::DEFAULT_CONFIG_FILE . '" config found. Should we generate it for you?',
'yes'
);
Expand All @@ -77,7 +77,7 @@ public function createConfig(string $projectDirectory): void
$configContents = $this->replacePathsContents($configContents, $projectDirectory);

FileSystem::write($commonRectorConfigPath, $configContents, null);
$this->symfonyStyle->success('The config is added now. Re-run command to make Rector do the work!');
$this->rectorStyle->success('The config is added now. Re-run command to make Rector do the work!');
}

public function areSomeRectorsLoaded(): bool
Expand Down
8 changes: 4 additions & 4 deletions src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Rector\Agentic\TerminalDetector;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\Style\RectorStyle;
use Rector\FileSystem\FilePathFilter;
use Rector\ValueObject\Configuration;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Webmozart\Assert\Assert;

/**
Expand All @@ -19,7 +19,7 @@
final readonly class ConfigurationFactory
{
public function __construct(
private SymfonyStyle $symfonyStyle,
private RectorStyle $rectorStyle,
private OnlyRuleResolver $onlyRuleResolver,
private FilePathFilter $filePathFilter,
) {
Expand Down Expand Up @@ -76,7 +76,7 @@ public function createFromInput(InputInterface $input): Configuration

$onlySuffix = $input->getOption(Option::ONLY_SUFFIX);
if ($onlySuffix !== null) {
$this->symfonyStyle->warning(
$this->rectorStyle->warning(
'The "--only-suffix" option is deprecated and will be removed. Use "--filter" instead, e.g. --filter="*Controller.php"'
);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ private function shouldShowProgressBar(InputInterface $input, string $outputForm
return false;
}

if ($this->symfonyStyle->isVerbose()) {
if ($this->rectorStyle->isVerbose()) {
return false;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Console/Command/ComposerBasedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Rector\Composer\InstalledPackageResolver;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\Style\RectorStyle;
use Rector\Contract\Rector\RectorInterface;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerBoundRuleConfiguration;
Expand All @@ -18,7 +19,6 @@
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @see \Rector\Tests\Console\Command\ComposerBasedCommandTest
Expand All @@ -29,7 +29,7 @@ final class ComposerBasedCommand extends Command
* @param RectorInterface[] $rectors
*/
public function __construct(
private readonly SymfonyStyle $symfonyStyle,
private readonly RectorStyle $rectorStyle,
private readonly InstalledPackageResolver $installedPackageResolver,
private readonly array $rectors
) {
Expand All @@ -48,22 +48,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$configurationTableRows = $this->createConfigurationTableRows();

if ($tableRows === [] && $configurationTableRows === []) {
$this->symfonyStyle->warning('No composer package bound rule is loaded');
$this->rectorStyle->warning('No composer package bound rule is loaded');

return Command::SUCCESS;
}

if ($tableRows !== []) {
$this->symfonyStyle->title('Composer package bound rules');
$this->symfonyStyle->table(['Rule', 'Package', 'Requires', 'Installed', 'Active'], $tableRows);
$this->rectorStyle->title('Composer package bound rules');
$this->rectorStyle->table(['Rule', 'Package', 'Requires', 'Installed', 'Active'], $tableRows);
}

if ($configurationTableRows !== []) {
$this->symfonyStyle->title('Composer package bound rule configuration');
$this->rectorStyle->title('Composer package bound rule configuration');

$headers = ['Rule', 'Package', 'Requires', 'Installed', 'Active'];

$table = $this->symfonyStyle->createTable();
$table = $this->rectorStyle->createTable();
$table->setHeaders($headers);
$table->setRows($this->createConfigurationDisplayRows($configurationTableRows));

Expand All @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$allTableRows = [...$tableRows, ...$configurationTableRows];
$activeCount = count(array_filter($allTableRows, static fn (array $tableRow): bool => $tableRow[4] === 'yes'));

$this->symfonyStyle->note(
$this->rectorStyle->note(
sprintf('%d of %d composer package bound items are active', $activeCount, count($allTableRows))
);

Expand Down
Loading
Loading