[DX] Make progress bar less verbose on CI (#1797)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tomas Votruba 2022-02-11 13:06:34 +01:00 committed by GitHub
parent 03ce06db76
commit 4f13982aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 153 additions and 106 deletions

View File

@ -3,6 +3,7 @@
declare(strict_types=1);
use Composer\Semver\VersionParser;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English\InflectorFactory;
use Ergebnis\Json\Printer\Printer;
@ -28,13 +29,13 @@ use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\Core\Console\ConsoleApplication;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
@ -90,7 +91,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(CloningVisitor::class);
$services->set(NodeFinder::class);
$services->set(SymfonyStyle::class)
$services->set(RectorConsoleOutputStyle::class)
->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
$services->set(Parser::class)

View File

@ -113,9 +113,9 @@ final class PhpDocInfoFactory
}
$phpDocChildNodes = $phpDocNode->children;
$lastChildNode = array_pop($phpDocChildNodes);
$phpDocChildNode = array_pop($phpDocChildNodes);
$startAndEnd = $lastChildNode->getAttribute(PhpDocAttributeKey::START_AND_END);
$startAndEnd = $phpDocChildNode->getAttribute(PhpDocAttributeKey::START_AND_END);
if ($startAndEnd instanceof StartAndEnd) {
$phpDocNode->setAttribute(PhpDocAttributeKey::LAST_PHP_DOC_TOKEN_POSITION, $startAndEnd->getEnd());

View File

@ -27,7 +27,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
private const ON_LINE_REGEX = '# on line #';
public function __construct(
private readonly OutputStyleInterface $outputStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly RectorsChangelogResolver $rectorsChangelogResolver
) {
}
@ -47,11 +47,11 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
// to keep space between progress bar and success message
if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) {
$this->outputStyle->newline();
$this->rectorOutputStyle->newLine();
}
$message = $this->createSuccessMessage($processResult, $configuration);
$this->outputStyle->success($message);
$this->rectorOutputStyle->success($message);
}
public function getName(): string
@ -72,7 +72,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
ksort($fileDiffs);
$message = sprintf('%d file%s with changes', count($fileDiffs), count($fileDiffs) === 1 ? '' : 's');
$this->outputStyle->title($message);
$this->rectorOutputStyle->title($message);
$i = 0;
foreach ($fileDiffs as $fileDiff) {
@ -86,16 +86,16 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
$message = sprintf('<options=bold>%d) %s</>', ++$i, $relativeFilePath);
$this->outputStyle->writeln($message);
$this->outputStyle->newline();
$this->outputStyle->writeln($fileDiff->getDiffConsoleFormatted());
$this->rectorOutputStyle->writeln($message);
$this->rectorOutputStyle->newLine();
$this->rectorOutputStyle->writeln($fileDiff->getDiffConsoleFormatted());
$rectorsChangelogsLines = $this->createRectorChangelogLines($fileDiff);
if ($fileDiff->getRectorChanges() !== []) {
$this->outputStyle->writeln('<options=underscore>Applied rules:</>');
$this->outputStyle->listing($rectorsChangelogsLines);
$this->outputStyle->newline();
$this->rectorOutputStyle->writeln('<options=underscore>Applied rules:</>');
$this->rectorOutputStyle->listing($rectorsChangelogsLines);
$this->rectorOutputStyle->newLine();
}
}
}
@ -121,7 +121,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
$message .= ' On line: ' . $error->getLine();
}
$this->outputStyle->error($message);
$this->rectorOutputStyle->error($message);
}
}
@ -129,12 +129,12 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
{
if ($processResult->getAddedFilesCount() !== 0) {
$message = sprintf('%d files were added', $processResult->getAddedFilesCount());
$this->outputStyle->note($message);
$this->rectorOutputStyle->note($message);
}
if ($processResult->getRemovedFilesCount() !== 0) {
$message = sprintf('%d files were removed', $processResult->getRemovedFilesCount());
$this->outputStyle->note($message);
$this->rectorOutputStyle->note($message);
}
$this->reportRemovedNodes($processResult);
@ -154,7 +154,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
}
$message = sprintf('%d nodes were removed', $processResult->getRemovedNodeCount());
$this->outputStyle->warning($message);
$this->rectorOutputStyle->warning($message);
}
private function createSuccessMessage(ProcessResult $processResult, Configuration $configuration): string

View File

@ -11,7 +11,6 @@ use Rector\Core\Logging\CurrentRectorProvider;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\Skipper\Skipper\Skipper;
final class PostFileProcessor
@ -28,7 +27,6 @@ final class PostFileProcessor
private readonly Skipper $skipper,
private readonly CurrentFileProvider $currentFileProvider,
private readonly CurrentRectorProvider $currentRectorProvider,
private readonly SymfonyStyle $symfonyStyle,
array $postRectors
) {
$this->postRectors = $this->sortByPriority($postRectors);
@ -46,7 +44,6 @@ final class PostFileProcessor
}
$this->currentRectorProvider->changeCurrentRector($postRector);
$this->notifyPostRector($postRector);
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($postRector);
@ -87,14 +84,4 @@ final class PostFileProcessor
$smartFileInfo = $file->getSmartFileInfo();
return $this->skipper->shouldSkipElementAndFileInfo($postRector, $smartFileInfo);
}
private function notifyPostRector(PostRectorInterface $postRector): void
{
if (! $this->symfonyStyle->isVerbose()) {
return;
}
$message = sprintf(' [%s] %s', 'post rector', $postRector::class);
$this->symfonyStyle->writeln($message);
}
}

View File

@ -6,16 +6,16 @@ namespace Rector\VersionBonding\Application;
use Nette\Utils\Strings;
use PHPStan\Php\PhpVersion;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Php\PhpVersionProvider;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
final class MissedRectorDueVersionChecker
{
public function __construct(
private readonly PhpVersionProvider $phpVersionProvider,
private readonly SymfonyStyle $symfonyStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
) {
}
@ -39,7 +39,7 @@ final class MissedRectorDueVersionChecker
'Do you want to run them? Make "require" > "php" in `composer.json` higher,%sor add "Option::PHP_VERSION_FEATURES" parameter to your `rector.php`.',
PHP_EOL
);
$this->symfonyStyle->note($solutionMessage);
$this->rectorOutputStyle->note($solutionMessage);
}
/**
@ -70,7 +70,7 @@ final class MissedRectorDueVersionChecker
*/
private function reportMissedRectors(array $minPhpVersions): void
{
if (! $this->symfonyStyle->isVerbose()) {
if (! $this->rectorOutputStyle->isVerbose()) {
return;
}
@ -79,7 +79,7 @@ final class MissedRectorDueVersionChecker
$shortRectorClass = Strings::after($minPhpVersion::class, '\\', -1);
$rectorMessage = sprintf(' * [%s] %s', $phpVersion->getVersionString(), $shortRectorClass);
$this->symfonyStyle->writeln($rectorMessage);
$this->rectorOutputStyle->writeln($rectorMessage);
}
}
@ -98,6 +98,6 @@ final class MissedRectorDueVersionChecker
PHP_EOL
);
$this->symfonyStyle->warning($warningMessage);
$this->rectorOutputStyle->warning($warningMessage);
}
}

View File

@ -603,3 +603,6 @@ parameters:
-
message: '#Array with keys is not allowed\. Use value object to pass data instead#'
path: packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php
# false positive
- '#Property Rector\\Core\\Tests\\Issues\\PhpTagsAddedToBlade\\PhpTagsAddedToBladeTest\:\:\$applicationFileProcessor \(Rector\\Core\\Application\\ApplicationFileProcessor\) does not accept T#'

View File

@ -8,6 +8,7 @@ use PHPStan\Analyser\NodeScopeResolver;
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Configuration\Option;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\ValueObject\Application\File;
use Rector\Core\ValueObject\Configuration;
@ -18,7 +19,6 @@ use Rector\FileFormatter\FileFormatter;
use Rector\Parallel\Application\ParallelFileProcessor;
use Rector\Parallel\ValueObject\Bridge;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\EasyParallel\CpuCoreCountProvider;
use Symplify\EasyParallel\Exception\ParallelShouldNotHappenException;
use Symplify\EasyParallel\FileSystem\FilePathNormalizer;
@ -49,7 +49,7 @@ final class ApplicationFileProcessor
private readonly FileDiffFileDecorator $fileDiffFileDecorator,
private readonly FileFormatter $fileFormatter,
private readonly RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
private readonly SymfonyStyle $symfonyStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly FileFactory $fileFactory,
private readonly NodeScopeResolver $nodeScopeResolver,
private readonly ParametersMerger $parametersMerger,
@ -115,7 +115,7 @@ final class ApplicationFileProcessor
{
if ($configuration->shouldShowProgressBar()) {
$fileCount = count($files);
$this->symfonyStyle->progressStart($fileCount);
$this->rectorOutputStyle->progressStart($fileCount);
}
$systemErrorsAndFileDiffs = [
@ -135,7 +135,7 @@ final class ApplicationFileProcessor
// progress bar +1
if ($configuration->shouldShowProgressBar()) {
$this->symfonyStyle->progressAdvance();
$this->rectorOutputStyle->progressAdvance();
}
}
@ -229,11 +229,11 @@ final class ApplicationFileProcessor
if (! $isProgressBarStarted) {
$fileCount = count($filePaths);
$this->symfonyStyle->progressStart($fileCount);
$this->rectorOutputStyle->progressStart($fileCount);
$isProgressBarStarted = true;
}
$this->symfonyStyle->progressAdvance($stepCount);
$this->rectorOutputStyle->progressAdvance($stepCount);
// running in parallel here → nothing else to do
};

View File

@ -9,6 +9,7 @@ use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
use Rector\Core\Application\FileProcessor;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Enum\ApplicationPhase;
use Rector\Core\Exception\ShouldNotHappenException;
@ -21,7 +22,6 @@ use Rector\Core\ValueObject\Reporting\FileDiff;
use Rector\Parallel\ValueObject\Bridge;
use Rector\PostRector\Application\PostFileProcessor;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;
final class PhpFileProcessor implements FileProcessorInterface
@ -30,7 +30,7 @@ final class PhpFileProcessor implements FileProcessorInterface
private readonly FormatPerservingPrinter $formatPerservingPrinter,
private readonly FileProcessor $fileProcessor,
private readonly RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
private readonly SymfonyStyle $symfonyStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly FileDiffFileDecorator $fileDiffFileDecorator,
private readonly CurrentFileProvider $currentFileProvider,
private readonly PostFileProcessor $postFileProcessor,
@ -133,7 +133,7 @@ final class PhpFileProcessor implements FileProcessorInterface
);
return [$autoloadSystemError];
} catch (Throwable $throwable) {
if ($this->symfonyStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
if ($this->rectorOutputStyle->isVerbose() || StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $throwable;
}
@ -167,13 +167,13 @@ final class PhpFileProcessor implements FileProcessorInterface
private function notifyPhase(File $file, ApplicationPhase $applicationPhase): void
{
if (! $this->symfonyStyle->isVerbose()) {
if (! $this->rectorOutputStyle->isVerbose()) {
return;
}
$smartFileInfo = $file->getSmartFileInfo();
$relativeFilePath = $smartFileInfo->getRelativeFilePathFromDirectory(getcwd());
$message = sprintf('[%s] %s', $applicationPhase, $relativeFilePath);
$this->symfonyStyle->writeln($message);
$this->rectorOutputStyle->writeln($message);
}
}

View File

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Rector\Core\Application\FileSystem;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\PhpParser\Printer\NodesWithFileDestinationPrinter;
use Rector\Core\ValueObject\Configuration;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\SmartFileSystem\SmartFileSystem;
/**
@ -18,7 +18,7 @@ final class RemovedAndAddedFilesProcessor
private readonly SmartFileSystem $smartFileSystem,
private readonly NodesWithFileDestinationPrinter $nodesWithFileDestinationPrinter,
private readonly RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
private readonly SymfonyStyle $symfonyStyle
private readonly OutputStyleInterface $rectorOutputStyle
) {
}
@ -38,10 +38,10 @@ final class RemovedAndAddedFilesProcessor
if ($configuration->isDryRun()) {
$message = sprintf('File "%s" will be removed', $relativePath);
$this->symfonyStyle->warning($message);
$this->rectorOutputStyle->warning($message);
} else {
$message = sprintf('File "%s" was removed', $relativePath);
$this->symfonyStyle->warning($message);
$this->rectorOutputStyle->warning($message);
$this->smartFileSystem->remove($removedFile->getPathname());
}
}
@ -52,14 +52,14 @@ final class RemovedAndAddedFilesProcessor
foreach ($this->removedAndAddedFilesCollector->getAddedFilesWithContent() as $addedFileWithContent) {
if ($configuration->isDryRun()) {
$message = sprintf('File "%s" will be added', $addedFileWithContent->getFilePath());
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
} else {
$this->smartFileSystem->dumpFile(
$addedFileWithContent->getFilePath(),
$addedFileWithContent->getFileContent()
);
$message = sprintf('File "%s" was added', $addedFileWithContent->getFilePath());
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
}
}
}
@ -73,11 +73,11 @@ final class RemovedAndAddedFilesProcessor
if ($configuration->isDryRun()) {
$message = sprintf('File "%s" will be added', $addedFileWithNode->getFilePath());
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
} else {
$this->smartFileSystem->dumpFile($addedFileWithNode->getFilePath(), $fileContent);
$message = sprintf('File "%s" was added', $addedFileWithNode->getFilePath());
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
}
}
}
@ -93,7 +93,7 @@ final class RemovedAndAddedFilesProcessor
$movedFile->getFilePath(),
$movedFile->getNewFilePath()
);
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
} else {
$this->smartFileSystem->dumpFile($movedFile->getNewFilePath(), $fileContent);
$this->smartFileSystem->remove($movedFile->getFilePath());
@ -103,7 +103,7 @@ final class RemovedAndAddedFilesProcessor
$movedFile->getFilePath(),
$movedFile->getNewFilePath()
);
$this->symfonyStyle->note($message);
$this->rectorOutputStyle->note($message);
}
}
}

View File

@ -5,16 +5,16 @@ declare(strict_types=1);
namespace Rector\Core\Configuration;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\ValueObject\Configuration;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
final class ConfigurationFactory
{
public function __construct(
private readonly ParameterProvider $parameterProvider,
private readonly SymfonyStyle $symfonyStyle
private readonly OutputStyleInterface $rectorOutputStyle
) {
}
@ -74,7 +74,7 @@ final class ConfigurationFactory
return false;
}
if ($this->symfonyStyle->isVerbose()) {
if ($this->rectorOutputStyle->isVerbose()) {
return false;
}

View File

@ -6,6 +6,7 @@ namespace Rector\Core\Console\Command;
use Nette\Utils\Strings;
use Rector\Core\Configuration\Option;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Template\TemplateResolverInterface;
use Rector\Core\Exception\Template\TemplateTypeNotFoundException;
use Rector\Core\Php\PhpVersionProvider;
@ -15,7 +16,6 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\SmartFileSystem\FileSystemGuard;
use Symplify\SmartFileSystem\SmartFileSystem;
@ -27,7 +27,7 @@ final class InitCommand extends Command
public function __construct(
private readonly FileSystemGuard $fileSystemGuard,
private readonly SmartFileSystem $smartFileSystem,
private readonly SymfonyStyle $symfonyStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly array $templateResolvers,
private readonly PhpVersionProvider $phpVersionProvider
) {
@ -59,7 +59,7 @@ final class InitCommand extends Command
$doesFileExist = $this->smartFileSystem->exists($rectorRootFilePath);
if ($doesFileExist) {
$this->symfonyStyle->warning('Config file "rector.php" already exists');
$this->rectorOutputStyle->warning('Config file "rector.php" already exists');
} else {
$this->smartFileSystem->copy($rectorTemplateFilePath, $rectorRootFilePath);
@ -74,7 +74,7 @@ final class InitCommand extends Command
);
$this->smartFileSystem->dumpFile($rectorRootFilePath, $fileContent);
$this->symfonyStyle->success('"rector.php" config file was added');
$this->rectorOutputStyle->success('"rector.php" config file was added');
}
return Command::SUCCESS;

View File

@ -11,6 +11,7 @@ use Rector\Core\Autoloading\AdditionalAutoloader;
use Rector\Core\Autoloading\BootstrapFilesIncluder;
use Rector\Core\Configuration\Option;
use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Reporting\MissingRectorRulesReporter;
@ -25,7 +26,6 @@ use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
final class ProcessCommand extends AbstractProcessCommand
@ -44,7 +44,7 @@ final class ProcessCommand extends AbstractProcessCommand
private readonly MissedRectorDueVersionChecker $missedRectorDueVersionChecker,
private readonly EmptyConfigurableRectorChecker $emptyConfigurableRectorChecker,
private readonly OutputFormatterCollector $outputFormatterCollector,
private readonly SymfonyStyle $symfonyStyle,
private readonly OutputStyleInterface $rectorOutputStyle,
private readonly MemoryLimiter $memoryLimiter,
private readonly array $rectors
) {
@ -71,7 +71,7 @@ final class ProcessCommand extends AbstractProcessCommand
// disable console output in case of json output formatter
if ($configuration->getOutputFormat() === JsonOutputFormatter::NAME) {
$this->symfonyStyle->setVerbosity(OutputInterface::VERBOSITY_QUIET);
$this->rectorOutputStyle->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
// register autoloaded and included files

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Rector\Core\Console\Output;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* This services helps to abstract from Symfony, and allow custom output formatters to use this Rector internal class.
@ -14,43 +14,53 @@ use Symfony\Component\Console\Style\SymfonyStyle;
final class RectorOutputStyle implements OutputStyleInterface
{
public function __construct(
private readonly SymfonyStyle $symfonyStyle
private readonly 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->symfonyStyle->error($message);
$this->rectorConsoleOutputStyle->error($message);
}
public function warning(string $message): void
{
$this->symfonyStyle->warning($message);
$this->rectorConsoleOutputStyle->warning($message);
}
public function success(string $message): void
{
$this->symfonyStyle->success($message);
$this->rectorConsoleOutputStyle->success($message);
}
public function note(string $message): void
{
$this->symfonyStyle->note($message);
$this->rectorConsoleOutputStyle->note($message);
}
public function title(string $message): void
{
$this->symfonyStyle->title($message);
$this->rectorConsoleOutputStyle->title($message);
}
public function writeln(string $message): void
{
$this->symfonyStyle->writeln($message);
$this->rectorConsoleOutputStyle->writeln($message);
}
public function newline(int $count = 1): void
public function newLine(int $count = 1): void
{
$this->symfonyStyle->newLine($count);
$this->rectorConsoleOutputStyle->newLine($count);
}
/**
@ -58,6 +68,21 @@ final class RectorOutputStyle implements OutputStyleInterface
*/
public function listing(array $elements): void
{
$this->symfonyStyle->listing($elements);
$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

@ -5,11 +5,17 @@ declare(strict_types=1);
namespace Rector\Core\Console\Style;
use OndraM\CiDetector\CiDetector;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
final class RectorConsoleOutputStyle extends SymfonyStyle
{
/**
* @var mixed|ProgressBar
*/
public $progressBar;
private bool|null $isCiDetected = null;
/**
@ -27,16 +33,26 @@ final class RectorConsoleOutputStyle extends SymfonyStyle
$progressBar->minSecondsBetweenRedraws(15);
$progressBar->maxSecondsBetweenRedraws(30);
} elseif (DIRECTORY_SEPARATOR === '\\') {
// windows
$progressBar->minSecondsBetweenRedraws(0.5);
$progressBar->maxSecondsBetweenRedraws(2);
} else {
// *nix
$progressBar->minSecondsBetweenRedraws(0.1);
$progressBar->maxSecondsBetweenRedraws(0.5);
}
$this->progressBar = $progressBar;
return $progressBar;
}
public function progressAdvance(int $step = 1): void
{
$progressBar = $this->getProgressBar();
$progressBar->advance($step);
}
private function isCiDetected(): bool
{
if ($this->isCiDetected === null) {
@ -46,4 +62,9 @@ final class RectorConsoleOutputStyle extends SymfonyStyle
return $this->isCiDetected;
}
private function getProgressBar(): ProgressBar
{
return $this->progressBar ?? throw new RuntimeException('The ProgressBar is not started.');
}
}

View File

@ -18,10 +18,20 @@ interface OutputStyleInterface
public function writeln(string $message): void;
public function newline(int $count = 1): 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

@ -22,6 +22,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Exclusion\ExclusionManager;
@ -46,7 +47,6 @@ use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\PostRector\Collector\NodesToRemoveCollector;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\Service\Attribute\Required;
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
@ -103,7 +103,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
private SymfonyStyle $symfonyStyle;
private OutputStyleInterface $rectorOutputStyle;
private ExclusionManager $exclusionManager;
@ -142,7 +142,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
NodeFactory $nodeFactory,
PhpDocInfoFactory $phpDocInfoFactory,
SymfonyStyle $symfonyStyle,
OutputStyleInterface $rectorOutputStyle,
PhpVersionProvider $phpVersionProvider,
ExclusionManager $exclusionManager,
StaticTypeMapper $staticTypeMapper,
@ -169,7 +169,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeFactory = $nodeFactory;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->symfonyStyle = $symfonyStyle;
$this->rectorOutputStyle = $rectorOutputStyle;
$this->phpVersionProvider = $phpVersionProvider;
$this->exclusionManager = $exclusionManager;
$this->staticTypeMapper = $staticTypeMapper;
@ -479,7 +479,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
private function printDebugApplying(): void
{
if (! $this->symfonyStyle->isDebug()) {
if (! $this->rectorOutputStyle->isDebug()) {
return;
}
@ -489,7 +489,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
// prevent spamming with the same class over and over
// indented on purpose to improve log nesting under [refactoring]
$this->symfonyStyle->writeln(' [applying] ' . static::class);
$this->rectorOutputStyle->writeln(' [applying] ' . static::class);
$this->previousAppliedClass = static::class;
}

View File

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Rector\Core\Reporting;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
final class MissingRectorRulesReporter
{
@ -17,7 +17,7 @@ final class MissingRectorRulesReporter
*/
public function __construct(
private readonly array $rectors,
private readonly SymfonyStyle $symfonyStyle
private readonly OutputStyleInterface $rectorOutputStyle
) {
}
@ -45,19 +45,19 @@ final class MissingRectorRulesReporter
public function report(): void
{
$this->symfonyStyle->warning('We could not find any Rector rules to run. You have 2 options to add them:');
$this->rectorOutputStyle->warning('We could not find any Rector rules to run. You have 2 options to add them:');
$this->symfonyStyle->title('1. Add single rule to "rector.php"');
$this->symfonyStyle->writeln(' $services = $containerConfigurator->services();');
$this->symfonyStyle->writeln(' $services->set(...);');
$this->symfonyStyle->newLine(1);
$this->rectorOutputStyle->title('1. Add single rule to "rector.php"');
$this->rectorOutputStyle->writeln(' $services = $containerConfigurator->services();');
$this->rectorOutputStyle->writeln(' $services->set(...);');
$this->rectorOutputStyle->newLine(1);
$this->symfonyStyle->title('2. Add set of rules to "rector.php"');
$this->symfonyStyle->writeln(' $containerConfigurator->import(SetList::...);');
$this->symfonyStyle->newLine(1);
$this->rectorOutputStyle->title('2. Add set of rules to "rector.php"');
$this->rectorOutputStyle->writeln(' $containerConfigurator->import(SetList::...);');
$this->rectorOutputStyle->newLine(1);
$this->symfonyStyle->title('Missing "rector.php" in your project? Let Rector create it for you');
$this->symfonyStyle->writeln(' vendor/bin/rector init');
$this->symfonyStyle->newLine();
$this->rectorOutputStyle->title('Missing "rector.php" in your project? Let Rector create it for you');
$this->rectorOutputStyle->writeln(' vendor/bin/rector init');
$this->rectorOutputStyle->newLine();
}
}

View File

@ -4,15 +4,15 @@ declare(strict_types=1);
namespace Rector\Core\Validation;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Symfony\Component\Console\Style\SymfonyStyle;
final class EmptyConfigurableRectorChecker
{
public function __construct(
private readonly EmptyConfigurableRectorCollector $emptyConfigurableRectorCollector,
private readonly SymfonyStyle $symfonyStyle
private readonly OutputStyleInterface $rectorOutputStyle
) {
}
@ -29,11 +29,11 @@ final class EmptyConfigurableRectorChecker
'Do you want to run them?%sConfigure them in `rector.php` with "...->configure(...);"',
PHP_EOL
);
$this->symfonyStyle->note($solutionMessage);
$this->rectorOutputStyle->note($solutionMessage);
if (! $this->symfonyStyle->isVerbose()) {
if (! $this->rectorOutputStyle->isVerbose()) {
// ensure there is new line after progress bar and report : "[OK] Rector is done!" with add a space
$this->symfonyStyle->write(' ');
$this->rectorOutputStyle->writeln(' ');
}
}
@ -46,10 +46,10 @@ final class EmptyConfigurableRectorChecker
'Your project contains %d configurable rector rules that are skipped as need to be configured to run.',
count($emptyConfigurableRectorClasses)
);
$this->symfonyStyle->warning($warningMessage);
$this->rectorOutputStyle->warning($warningMessage);
foreach ($emptyConfigurableRectorClasses as $emptyConfigurableRectorClass) {
$this->symfonyStyle->writeln(' * ' . $emptyConfigurableRectorClass);
$this->rectorOutputStyle->writeln(' * ' . $emptyConfigurableRectorClass);
}
// to take time to absorb it