mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Dislay file names in debug mode, merge ConsoleStyle to SymfonyStyle
This commit is contained in:
parent
db680aabed
commit
3c4a110f6a
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Rector\Console\Application;
|
use Rector\Console\Application;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symplify\PackageBuilder\Console\ThrowableRenderer;
|
use Symplify\PackageBuilder\Console\ThrowableRenderer;
|
||||||
|
|
||||||
// Performance boost
|
// Performance boost
|
||||||
@ -15,8 +17,12 @@ try {
|
|||||||
/** @var ContainerInterface $container */
|
/** @var ContainerInterface $container */
|
||||||
$container = require_once __DIR__ . '/container.php';
|
$container = require_once __DIR__ . '/container.php';
|
||||||
|
|
||||||
|
/** this calls @see \Symfony\Component\Console\Application::configureIO() and configure Input + Output services */
|
||||||
|
$input = $container->get(InputInterface::class);
|
||||||
|
$output = $container->get(OutputInterface::class);
|
||||||
|
|
||||||
$application = $container->get(Application::class);
|
$application = $container->get(Application::class);
|
||||||
exit($application->run());
|
exit($application->run($input, $output));
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
(new ThrowableRenderer())->render($throwable);
|
(new ThrowableRenderer())->render($throwable);
|
||||||
exit($throwable->getCode());
|
exit($throwable->getCode());
|
||||||
|
@ -5,13 +5,13 @@ namespace Rector\ContributorTools\Command;
|
|||||||
use Nette\Utils\FileSystem;
|
use Nette\Utils\FileSystem;
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
use Rector\CodingStyle\AfterRectorCodingStyle;
|
use Rector\CodingStyle\AfterRectorCodingStyle;
|
||||||
use Rector\Console\ConsoleStyle;
|
|
||||||
use Rector\ContributorTools\Configuration\Configuration;
|
use Rector\ContributorTools\Configuration\Configuration;
|
||||||
use Rector\ContributorTools\Configuration\ConfigurationFactory;
|
use Rector\ContributorTools\Configuration\ConfigurationFactory;
|
||||||
use Rector\ContributorTools\TemplateVariablesFactory;
|
use Rector\ContributorTools\TemplateVariablesFactory;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||||
use Symplify\PackageBuilder\Console\ShellCode;
|
use Symplify\PackageBuilder\Console\ShellCode;
|
||||||
@ -44,9 +44,9 @@ final class CreateRectorCommand extends Command
|
|||||||
private $generatedFiles = [];
|
private $generatedFiles = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConsoleStyle
|
* @var SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private $consoleStyle;
|
private $symfonyStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigurationFactory
|
* @var ConfigurationFactory
|
||||||
@ -69,14 +69,14 @@ final class CreateRectorCommand extends Command
|
|||||||
private $templateVariablesFactory;
|
private $templateVariablesFactory;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ConsoleStyle $consoleStyle,
|
SymfonyStyle $symfonyStyle,
|
||||||
ConfigurationFactory $configurationFactory,
|
ConfigurationFactory $configurationFactory,
|
||||||
FinderSanitizer $finderSanitizer,
|
FinderSanitizer $finderSanitizer,
|
||||||
AfterRectorCodingStyle $afterRectorCodingStyle,
|
AfterRectorCodingStyle $afterRectorCodingStyle,
|
||||||
TemplateVariablesFactory $templateVariablesFactory
|
TemplateVariablesFactory $templateVariablesFactory
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->consoleStyle = $consoleStyle;
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
$this->configurationFactory = $configurationFactory;
|
$this->configurationFactory = $configurationFactory;
|
||||||
$this->finderSanitizer = $finderSanitizer;
|
$this->finderSanitizer = $finderSanitizer;
|
||||||
$this->afterRectorCodingStyle = $afterRectorCodingStyle;
|
$this->afterRectorCodingStyle = $afterRectorCodingStyle;
|
||||||
@ -190,11 +190,11 @@ final class CreateRectorCommand extends Command
|
|||||||
|
|
||||||
private function printSuccess(string $name): void
|
private function printSuccess(string $name): void
|
||||||
{
|
{
|
||||||
$this->consoleStyle->title(sprintf('New files generated for "%s"', $name));
|
$this->symfonyStyle->title(sprintf('New files generated for "%s"', $name));
|
||||||
sort($this->generatedFiles);
|
sort($this->generatedFiles);
|
||||||
$this->consoleStyle->listing($this->generatedFiles);
|
$this->symfonyStyle->listing($this->generatedFiles);
|
||||||
|
|
||||||
$this->consoleStyle->success(sprintf(
|
$this->symfonyStyle->success(sprintf(
|
||||||
'Now make these tests green again:%svendor/bin/phpunit %s',
|
'Now make these tests green again:%svendor/bin/phpunit %s',
|
||||||
PHP_EOL . PHP_EOL,
|
PHP_EOL . PHP_EOL,
|
||||||
$this->testCasePath
|
$this->testCasePath
|
||||||
|
@ -4,7 +4,6 @@ namespace Rector\Console\Command;
|
|||||||
|
|
||||||
use Nette\Loaders\RobotLoader;
|
use Nette\Loaders\RobotLoader;
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
use Rector\Console\ConsoleStyle;
|
|
||||||
use Rector\Console\Shell;
|
use Rector\Console\Shell;
|
||||||
use Rector\ConsoleDiffer\MarkdownDifferAndFormatter;
|
use Rector\ConsoleDiffer\MarkdownDifferAndFormatter;
|
||||||
use Rector\Contract\Rector\RectorInterface;
|
use Rector\Contract\Rector\RectorInterface;
|
||||||
@ -14,6 +13,7 @@ use ReflectionClass;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||||
use function Safe\ksort;
|
use function Safe\ksort;
|
||||||
@ -22,20 +22,20 @@ use function Safe\sprintf;
|
|||||||
final class GenerateRectorOverviewCommand extends Command
|
final class GenerateRectorOverviewCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ConsoleStyle
|
* @var SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private $consoleStyle;
|
private $symfonyStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MarkdownDifferAndFormatter
|
* @var MarkdownDifferAndFormatter
|
||||||
*/
|
*/
|
||||||
private $markdownDifferAndFormatter;
|
private $markdownDifferAndFormatter;
|
||||||
|
|
||||||
public function __construct(ConsoleStyle $consoleStyle, MarkdownDifferAndFormatter $markdownDifferAndFormatter)
|
public function __construct(SymfonyStyle $symfonyStyle, MarkdownDifferAndFormatter $markdownDifferAndFormatter)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->consoleStyle = $consoleStyle;
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
$this->markdownDifferAndFormatter = $markdownDifferAndFormatter;
|
$this->markdownDifferAndFormatter = $markdownDifferAndFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,23 +47,23 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->consoleStyle->writeln('# All Rectors Overview');
|
$this->symfonyStyle->writeln('# All Rectors Overview');
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
$this->consoleStyle->writeln('- [Projects](#projects)');
|
$this->symfonyStyle->writeln('- [Projects](#projects)');
|
||||||
$this->consoleStyle->writeln('- [General](#general)');
|
$this->symfonyStyle->writeln('- [General](#general)');
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
$this->consoleStyle->writeln('## Projects');
|
$this->symfonyStyle->writeln('## Projects');
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
$rectorsByGroup = $this->groupRectors($this->getProjectsRectors());
|
$rectorsByGroup = $this->groupRectors($this->getProjectsRectors());
|
||||||
$this->printRectorsByGroup($rectorsByGroup);
|
$this->printRectorsByGroup($rectorsByGroup);
|
||||||
|
|
||||||
$this->consoleStyle->writeln('---');
|
$this->symfonyStyle->writeln('---');
|
||||||
|
|
||||||
$this->consoleStyle->writeln('## General');
|
$this->symfonyStyle->writeln('## General');
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
$rectorsByGroup = $this->groupRectors($this->getGeneralRectors());
|
$rectorsByGroup = $this->groupRectors($this->getGeneralRectors());
|
||||||
$this->printRectorsByGroup($rectorsByGroup);
|
$this->printRectorsByGroup($rectorsByGroup);
|
||||||
@ -108,8 +108,8 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
$this->printGroupsMenu($rectorsByGroup);
|
$this->printGroupsMenu($rectorsByGroup);
|
||||||
|
|
||||||
foreach ($rectorsByGroup as $group => $rectors) {
|
foreach ($rectorsByGroup as $group => $rectors) {
|
||||||
$this->consoleStyle->writeln('## ' . $group);
|
$this->symfonyStyle->writeln('## ' . $group);
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
foreach ($rectors as $rector) {
|
foreach ($rectors as $rector) {
|
||||||
$this->printRector($rector);
|
$this->printRector($rector);
|
||||||
@ -206,28 +206,28 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
$escapedGroup = str_replace('\\', '', $group);
|
$escapedGroup = str_replace('\\', '', $group);
|
||||||
$escapedGroup = Strings::webalize($escapedGroup, '_');
|
$escapedGroup = Strings::webalize($escapedGroup, '_');
|
||||||
|
|
||||||
$this->consoleStyle->writeln(sprintf('- [%s](#%s)', $group, $escapedGroup));
|
$this->symfonyStyle->writeln(sprintf('- [%s](#%s)', $group, $escapedGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function printRector(RectorInterface $rector): void
|
private function printRector(RectorInterface $rector): void
|
||||||
{
|
{
|
||||||
$headline = $this->getRectorClassWithoutNamespace($rector);
|
$headline = $this->getRectorClassWithoutNamespace($rector);
|
||||||
$this->consoleStyle->writeln(sprintf('### `%s`', $headline));
|
$this->symfonyStyle->writeln(sprintf('### `%s`', $headline));
|
||||||
|
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
$this->consoleStyle->writeln(sprintf('- class: `%s`', get_class($rector)));
|
$this->symfonyStyle->writeln(sprintf('- class: `%s`', get_class($rector)));
|
||||||
|
|
||||||
$rectorDefinition = $rector->getDefinition();
|
$rectorDefinition = $rector->getDefinition();
|
||||||
if ($rectorDefinition->getDescription()) {
|
if ($rectorDefinition->getDescription()) {
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
$this->consoleStyle->writeln($rectorDefinition->getDescription());
|
$this->symfonyStyle->writeln($rectorDefinition->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($rectorDefinition->getCodeSamples() as $codeSample) {
|
foreach ($rectorDefinition->getCodeSamples() as $codeSample) {
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
|
|
||||||
if ($codeSample instanceof ConfiguredCodeSample) {
|
if ($codeSample instanceof ConfiguredCodeSample) {
|
||||||
$configuration = [
|
$configuration = [
|
||||||
@ -240,9 +240,9 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
|
|
||||||
$this->printCodeWrapped($configuration, 'yaml');
|
$this->printCodeWrapped($configuration, 'yaml');
|
||||||
|
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
$this->consoleStyle->writeln('↓');
|
$this->symfonyStyle->writeln('↓');
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
$diff = $this->markdownDifferAndFormatter->bareDiffAndFormatWithoutColors(
|
$diff = $this->markdownDifferAndFormatter->bareDiffAndFormatWithoutColors(
|
||||||
@ -252,7 +252,7 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
$this->printCodeWrapped($diff, 'diff');
|
$this->printCodeWrapped($diff, 'diff');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->newLine(1);
|
$this->symfonyStyle->newLine(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRectorClassWithoutNamespace(RectorInterface $rector): string
|
private function getRectorClassWithoutNamespace(RectorInterface $rector): string
|
||||||
@ -265,6 +265,6 @@ final class GenerateRectorOverviewCommand extends Command
|
|||||||
|
|
||||||
private function printCodeWrapped(string $content, string $format): void
|
private function printCodeWrapped(string $content, string $format): void
|
||||||
{
|
{
|
||||||
$this->consoleStyle->writeln(sprintf('```%s%s%s%s```', $format, PHP_EOL, rtrim($content), PHP_EOL));
|
$this->symfonyStyle->writeln(sprintf('```%s%s%s%s```', $format, PHP_EOL, rtrim($content), PHP_EOL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
namespace Rector\Console\Command;
|
namespace Rector\Console\Command;
|
||||||
|
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
use Rector\Console\ConsoleStyle;
|
|
||||||
use Rector\Console\Shell;
|
use Rector\Console\Shell;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||||
use function Safe\sort;
|
use function Safe\sort;
|
||||||
@ -17,13 +17,13 @@ use function Safe\sprintf;
|
|||||||
final class LevelsCommand extends Command
|
final class LevelsCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ConsoleStyle
|
* @var SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private $consoleStyle;
|
private $symfonyStyle;
|
||||||
|
|
||||||
public function __construct(ConsoleStyle $consoleStyle)
|
public function __construct(SymfonyStyle $symfonyStyle)
|
||||||
{
|
{
|
||||||
$this->consoleStyle = $consoleStyle;
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@ -43,8 +43,8 @@ final class LevelsCommand extends Command
|
|||||||
$levels = $this->filterLevelsByName($input, $levels);
|
$levels = $this->filterLevelsByName($input, $levels);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->title(sprintf('%d available levels:', count($levels)));
|
$this->symfonyStyle->title(sprintf('%d available levels:', count($levels)));
|
||||||
$this->consoleStyle->listing($levels);
|
$this->symfonyStyle->listing($levels);
|
||||||
|
|
||||||
return Shell::CODE_SUCCESS;
|
return Shell::CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ use Rector\Application\FileProcessor;
|
|||||||
use Rector\Autoloading\AdditionalAutoloader;
|
use Rector\Autoloading\AdditionalAutoloader;
|
||||||
use Rector\CodingStyle\AfterRectorCodingStyle;
|
use Rector\CodingStyle\AfterRectorCodingStyle;
|
||||||
use Rector\Configuration\Option;
|
use Rector\Configuration\Option;
|
||||||
use Rector\Console\ConsoleStyle;
|
|
||||||
use Rector\Console\Output\ProcessCommandReporter;
|
use Rector\Console\Output\ProcessCommandReporter;
|
||||||
use Rector\Console\Shell;
|
use Rector\Console\Shell;
|
||||||
use Rector\ConsoleDiffer\DifferAndFormatter;
|
use Rector\ConsoleDiffer\DifferAndFormatter;
|
||||||
@ -24,6 +23,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||||
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;
|
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;
|
||||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||||
@ -48,9 +48,9 @@ final class ProcessCommand extends Command
|
|||||||
private $fileProcessor;
|
private $fileProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConsoleStyle
|
* @var SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private $consoleStyle;
|
private $symfonyStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var FilesFinder
|
* @var FilesFinder
|
||||||
@ -104,7 +104,7 @@ final class ProcessCommand extends Command
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
FileProcessor $fileProcessor,
|
FileProcessor $fileProcessor,
|
||||||
ConsoleStyle $consoleStyle,
|
SymfonyStyle $symfonyStyle,
|
||||||
FilesFinder $phpFilesFinder,
|
FilesFinder $phpFilesFinder,
|
||||||
ProcessCommandReporter $processCommandReporter,
|
ProcessCommandReporter $processCommandReporter,
|
||||||
ParameterProvider $parameterProvider,
|
ParameterProvider $parameterProvider,
|
||||||
@ -119,7 +119,7 @@ final class ProcessCommand extends Command
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->fileProcessor = $fileProcessor;
|
$this->fileProcessor = $fileProcessor;
|
||||||
$this->consoleStyle = $consoleStyle;
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
$this->filesFinder = $phpFilesFinder;
|
$this->filesFinder = $phpFilesFinder;
|
||||||
$this->processCommandReporter = $processCommandReporter;
|
$this->processCommandReporter = $processCommandReporter;
|
||||||
$this->parameterProvider = $parameterProvider;
|
$this->parameterProvider = $parameterProvider;
|
||||||
@ -199,7 +199,7 @@ final class ProcessCommand extends Command
|
|||||||
$this->afterRectorCodingStyle->apply($source);
|
$this->afterRectorCodingStyle->apply($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->success('Rector is done!');
|
$this->symfonyStyle->success('Rector is done!');
|
||||||
|
|
||||||
return Shell::CODE_SUCCESS;
|
return Shell::CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -210,15 +210,22 @@ final class ProcessCommand extends Command
|
|||||||
private function processFileInfos(array $fileInfos, bool $shouldHideAutoloadErrors): void
|
private function processFileInfos(array $fileInfos, bool $shouldHideAutoloadErrors): void
|
||||||
{
|
{
|
||||||
$totalFiles = count($fileInfos);
|
$totalFiles = count($fileInfos);
|
||||||
$this->consoleStyle->title(sprintf('Processing %d file%s', $totalFiles, $totalFiles === 1 ? '' : 's'));
|
$this->symfonyStyle->title(sprintf('Processing %d file%s', $totalFiles, $totalFiles === 1 ? '' : 's'));
|
||||||
$this->consoleStyle->progressStart($totalFiles);
|
|
||||||
|
if (! $this->symfonyStyle->isVerbose()) {
|
||||||
|
$this->symfonyStyle->progressStart($totalFiles);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($fileInfos as $fileInfo) {
|
foreach ($fileInfos as $fileInfo) {
|
||||||
$this->processFileInfo($fileInfo, $shouldHideAutoloadErrors);
|
$this->processFileInfo($fileInfo, $shouldHideAutoloadErrors);
|
||||||
$this->consoleStyle->progressAdvance();
|
if ($this->symfonyStyle->isVerbose()) {
|
||||||
|
$this->symfonyStyle->writeln($fileInfo->getRealPath());
|
||||||
|
} else {
|
||||||
|
$this->symfonyStyle->progressAdvance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->newLine(2);
|
$this->symfonyStyle->newLine(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processFileInfo(SmartFileInfo $fileInfo, bool $shouldHideAutoloadErrors): void
|
private function processFileInfo(SmartFileInfo $fileInfo, bool $shouldHideAutoloadErrors): void
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Rector\Console;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
||||||
use function Safe\sprintf;
|
|
||||||
|
|
||||||
final class ConsoleStyle extends SymfonyStyle
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param string[] $elements
|
|
||||||
*/
|
|
||||||
public function listing(array $elements): void
|
|
||||||
{
|
|
||||||
$elements = array_map(function ($element) {
|
|
||||||
return sprintf(' - %s', $element);
|
|
||||||
}, $elements);
|
|
||||||
$this->writeln($elements);
|
|
||||||
$this->newLine();
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,19 +3,19 @@
|
|||||||
namespace Rector\Console\Output;
|
namespace Rector\Console\Output;
|
||||||
|
|
||||||
use Rector\Application\Error;
|
use Rector\Application\Error;
|
||||||
use Rector\Console\ConsoleStyle;
|
|
||||||
use Rector\Contract\Rector\RectorInterface;
|
use Rector\Contract\Rector\RectorInterface;
|
||||||
use Rector\NodeTraverser\RectorNodeTraverser;
|
use Rector\NodeTraverser\RectorNodeTraverser;
|
||||||
use Rector\Reporting\FileDiff;
|
use Rector\Reporting\FileDiff;
|
||||||
use Rector\YamlRector\YamlFileProcessor;
|
use Rector\YamlRector\YamlFileProcessor;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use function Safe\sprintf;
|
use function Safe\sprintf;
|
||||||
|
|
||||||
final class ProcessCommandReporter
|
final class ProcessCommandReporter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ConsoleStyle
|
* @var SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private $consoleStyle;
|
private $symfonyStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RectorNodeTraverser
|
* @var RectorNodeTraverser
|
||||||
@ -29,10 +29,10 @@ final class ProcessCommandReporter
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
RectorNodeTraverser $rectorNodeTraverser,
|
RectorNodeTraverser $rectorNodeTraverser,
|
||||||
ConsoleStyle $consoleStyle,
|
SymfonyStyle $symfonyStyle,
|
||||||
YamlFileProcessor $yamlFileProcessor
|
YamlFileProcessor $yamlFileProcessor
|
||||||
) {
|
) {
|
||||||
$this->consoleStyle = $consoleStyle;
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
$this->rectorNodeTraverser = $rectorNodeTraverser;
|
$this->rectorNodeTraverser = $rectorNodeTraverser;
|
||||||
$this->yamlFileProcessor = $yamlFileProcessor;
|
$this->yamlFileProcessor = $yamlFileProcessor;
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ final class ProcessCommandReporter
|
|||||||
{
|
{
|
||||||
$rectorCount = $this->rectorNodeTraverser->getRectorCount() + $this->yamlFileProcessor->getYamlRectorsCount();
|
$rectorCount = $this->rectorNodeTraverser->getRectorCount() + $this->yamlFileProcessor->getYamlRectorsCount();
|
||||||
|
|
||||||
$this->consoleStyle->title(sprintf('%d Loaded Rector%s', $rectorCount, $rectorCount === 1 ? '' : 's'));
|
$this->symfonyStyle->title(sprintf('%d Loaded Rector%s', $rectorCount, $rectorCount === 1 ? '' : 's'));
|
||||||
|
|
||||||
$allRectors = array_merge(
|
$allRectors = array_merge(
|
||||||
$this->rectorNodeTraverser->getRectors() + $this->yamlFileProcessor->getYamlRectors()
|
$this->rectorNodeTraverser->getRectors() + $this->yamlFileProcessor->getYamlRectors()
|
||||||
@ -51,7 +51,7 @@ final class ProcessCommandReporter
|
|||||||
return get_class($rector);
|
return get_class($rector);
|
||||||
}, $allRectors);
|
}, $allRectors);
|
||||||
|
|
||||||
$this->consoleStyle->listing($rectorClasses);
|
$this->symfonyStyle->listing($rectorClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,10 +63,10 @@ final class ProcessCommandReporter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->title(
|
$this->symfonyStyle->title(
|
||||||
sprintf('%d Changed file%s', count($changedFiles), count($changedFiles) === 1 ? '' : 's')
|
sprintf('%d Changed file%s', count($changedFiles), count($changedFiles) === 1 ? '' : 's')
|
||||||
);
|
);
|
||||||
$this->consoleStyle->listing($changedFiles);
|
$this->symfonyStyle->listing($changedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,16 +78,16 @@ final class ProcessCommandReporter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->title(
|
$this->symfonyStyle->title(
|
||||||
sprintf('%d file%s with changes', count($fileDiffs), count($fileDiffs) === 1 ? '' : 's')
|
sprintf('%d file%s with changes', count($fileDiffs), count($fileDiffs) === 1 ? '' : 's')
|
||||||
);
|
);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($fileDiffs as $fileDiff) {
|
foreach ($fileDiffs as $fileDiff) {
|
||||||
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $fileDiff->getFile()));
|
$this->symfonyStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $fileDiff->getFile()));
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
$this->consoleStyle->writeln($fileDiff->getDiff());
|
$this->symfonyStyle->writeln($fileDiff->getDiff());
|
||||||
$this->consoleStyle->newLine();
|
$this->symfonyStyle->newLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ final class ProcessCommandReporter
|
|||||||
$message .= ' On line: ' . $error->getLine();
|
$message .= ' On line: ' . $error->getLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->consoleStyle->error($message);
|
$this->symfonyStyle->error($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ services:
|
|||||||
# Symfony\Console
|
# Symfony\Console
|
||||||
Symfony\Component\Console\Style\SymfonyStyle: ~
|
Symfony\Component\Console\Style\SymfonyStyle: ~
|
||||||
Symfony\Component\Console\Input\ArgvInput: ~
|
Symfony\Component\Console\Input\ArgvInput: ~
|
||||||
|
Symfony\Component\Console\Input\InputInterface:
|
||||||
|
alias: 'Symfony\Component\Console\Input\ArgvInput'
|
||||||
Symfony\Component\Console\Output\ConsoleOutput: ~
|
Symfony\Component\Console\Output\ConsoleOutput: ~
|
||||||
Symfony\Component\Console\Output\OutputInterface:
|
Symfony\Component\Console\Output\OutputInterface:
|
||||||
alias: Symfony\Component\Console\Output\ConsoleOutput
|
alias: 'Symfony\Component\Console\Output\ConsoleOutput'
|
||||||
|
|
||||||
Symplify\PackageBuilder\FileSystem\FileSystem: ~
|
Symplify\PackageBuilder\FileSystem\FileSystem: ~
|
||||||
Symplify\PackageBuilder\FileSystem\FinderSanitizer: ~
|
Symplify\PackageBuilder\FileSystem\FinderSanitizer: ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user