diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index 1ec05f6705c..24c9bbb2321 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -60,7 +60,7 @@ jobs: - run: composer install --no-progress --ansi ## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future - - run: bin/rector process ${{ matrix.paths }} --ansi --no-progress-bar + - run: bin/rector process ${{ matrix.paths }} --ansi - run: vendor/bin/ecs check --fix --ansi diff --git a/bin/rector.php b/bin/rector.php index be08e546a69..0ce45cf7999 100755 --- a/bin/rector.php +++ b/bin/rector.php @@ -7,7 +7,7 @@ use Rector\ChangesReporting\Output\JsonOutputFormatter; use Rector\Core\Bootstrap\RectorConfigsResolver; use Rector\Core\Configuration\Option; use Rector\Core\Console\ConsoleApplication; -use Rector\Core\Console\Style\SymfonyStyleFactory; +use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory; use Rector\Core\DependencyInjection\RectorContainerFactory; use Rector\Core\Kernel\RectorKernel; use Symfony\Component\Console\Command\Command; @@ -59,9 +59,9 @@ try { ]); } else { // report fatal errors in console format - $symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller()); - $symfonyStyle = $symfonyStyleFactory->create(); - $symfonyStyle->error($throwable->getMessage()); + $rectorConsoleOutputStyleFactory = new RectorConsoleOutputStyleFactory(new PrivatesCaller()); + $rectorConsoleOutputStyle = $rectorConsoleOutputStyleFactory->create(); + $rectorConsoleOutputStyle->error($throwable->getMessage()); } exit(Command::FAILURE); diff --git a/composer.json b/composer.json index 6607444b5b4..e39bad042b0 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,13 @@ "composer/xdebug-handler": "^2.0|^3.0", "doctrine/inflector": "^2.0", "ergebnis/json-printer": "^3.2", + "helmich/typo3-typoscript-parser": "dev-master#0ccb3a6", "idiosyncratic/editorconfig": "^0.1.3", "myclabs/php-enum": "^1.8", "nette/neon": "^3.3.2", "nette/utils": "^3.2", "nikic/php-parser": "^4.13.2", + "ondram/ci-detector": "^4.1", "phpstan/phpdoc-parser": "^1.2", "phpstan/phpstan": "^1.4.2", "phpstan/phpstan-phpunit": "^1.0", @@ -46,7 +48,6 @@ "symfony/string": "^6.0", "symfony/yaml": "^5.4|^6.0", "symplify/astral": "^10.0.16", - "symplify/symplify-kernel": "^10.0.16", "symplify/autowire-array-parameter": "^10.0.16", "symplify/composer-json-manipulator": "^10.0.16", "symplify/console-color-diff": "^10.0.16", @@ -57,10 +58,10 @@ "symplify/skipper": "^10.0.16", "symplify/smart-file-system": "^10.0.16", "symplify/symfony-php-config": "^10.0.16", + "symplify/symplify-kernel": "^10.0.16", "symplify/vendor-patches": "^10.0.16", "tracy/tracy": "^2.9", - "webmozart/assert": "^1.10", - "helmich/typo3-typoscript-parser": "dev-master#0ccb3a6" + "webmozart/assert": "^1.10" }, "require-dev": { "brianium/paratest": "^6.3", diff --git a/config/services.php b/config/services.php index cf13e566b2c..8e061411aa6 100644 --- a/config/services.php +++ b/config/services.php @@ -28,6 +28,7 @@ use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser; use Rector\Caching\Cache; use Rector\Caching\CacheFactory; use Rector\Core\Console\ConsoleApplication; +use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory; use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector; use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator; @@ -38,7 +39,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura use function Symfony\Component\DependencyInjection\Loader\Configurator\service; use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser; use Symplify\PackageBuilder\Console\Command\CommandNaming; -use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory; use Symplify\PackageBuilder\Parameter\ParameterProvider; use Symplify\PackageBuilder\Php\TypeChecker; use Symplify\PackageBuilder\Reflection\PrivatesAccessor; @@ -61,6 +61,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->load('Rector\Core\\', __DIR__ . '/../src') ->exclude([ __DIR__ . '/../src/Rector', + __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', __DIR__ . '/../src/Exception', __DIR__ . '/../src/DependencyInjection/CompilerPass', __DIR__ . '/../src/DependencyInjection/Loader', @@ -89,6 +90,9 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(CloningVisitor::class); $services->set(NodeFinder::class); + $services->set(SymfonyStyle::class) + ->factory([service(RectorConsoleOutputStyleFactory::class), 'create']); + $services->set(Parser::class) ->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']); @@ -109,10 +113,6 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(StringFormatConverter::class); - $services->set(SymfonyStyleFactory::class); - $services->set(SymfonyStyle::class) - ->factory([service(SymfonyStyleFactory::class), 'create']); - $services->set(JsonFileSystem::class); $services->set(NodeConnectingVisitor::class); diff --git a/e2e/e2eTestRunner.php b/e2e/e2eTestRunner.php index 0d77aa62f04..a32105807c8 100644 --- a/e2e/e2eTestRunner.php +++ b/e2e/e2eTestRunner.php @@ -17,7 +17,7 @@ $autoloadFile = $projectRoot . '/vendor/autoload.php'; // so we can use helper classes here require_once __DIR__ . '/../vendor/autoload.php'; -$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi --no-progress-bar -a '. $autoloadFile . ' --clear-cache'; +$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi -a '. $autoloadFile . ' --clear-cache'; if (isset($argv[1]) && $argv[1] === '-c') { $e2eCommand .= ' -c ' . $argv[2]; diff --git a/src/Console/Command/ShowCommand.php b/src/Console/Command/ShowCommand.php index 18193f5f9af..1f589c9cb2a 100644 --- a/src/Console/Command/ShowCommand.php +++ b/src/Console/Command/ShowCommand.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Rector\Core\Console\Command; -use Rector\Core\Contract\Console\OutputStyleInterface; +use Rector\Core\Console\Output\RectorOutputStyle; use Rector\Core\Contract\Rector\RectorInterface; use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface; use Rector\PostRector\Contract\Rector\PostRectorInterface; @@ -19,7 +19,7 @@ final class ShowCommand extends Command * @param RectorInterface[] $rectors */ public function __construct( - private readonly OutputStyleInterface $outputStyle, + private readonly RectorOutputStyle $rectorOutputStyle, private readonly array $rectors ) { parent::__construct(); @@ -33,7 +33,7 @@ final class ShowCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $this->outputStyle->title('Loaded Rector rules'); + $this->rectorOutputStyle->title('Loaded Rector rules'); $rectors = array_filter( $this->rectors, @@ -54,20 +54,20 @@ final class ShowCommand extends Command PHP_EOL . PHP_EOL, PHP_EOL ); - $this->outputStyle->warning($warningMessage); + $this->rectorOutputStyle->warning($warningMessage); return self::FAILURE; } $rectorCount = count($rectors); foreach ($rectors as $rector) { - $this->outputStyle->writeln(' * ' . $rector::class); + $this->rectorOutputStyle->writeln(' * ' . $rector::class); } $message = sprintf('%d loaded Rectors', $rectorCount); - $this->outputStyle->success($message); + $this->rectorOutputStyle->success($message); - $this->outputStyle->error( + $this->rectorOutputStyle->error( 'The "show" command is deprecated and will be removed, as it was used only for more output on Rector run. Use the "--debug" option and process command for debugging output instead.' ); // to spot the error message diff --git a/src/Console/Style/RectorConsoleOutputStyle.php b/src/Console/Style/RectorConsoleOutputStyle.php new file mode 100644 index 00000000000..d836007cdfd --- /dev/null +++ b/src/Console/Style/RectorConsoleOutputStyle.php @@ -0,0 +1,49 @@ +setOverwrite(! $this->isCiDetected()); + + $isCiDetected = $this->isCiDetected(); + $progressBar->setOverwrite(! $isCiDetected); + + if ($isCiDetected) { + $progressBar->minSecondsBetweenRedraws(15); + $progressBar->maxSecondsBetweenRedraws(30); + } elseif (DIRECTORY_SEPARATOR === '\\') { + $progressBar->minSecondsBetweenRedraws(0.5); + $progressBar->maxSecondsBetweenRedraws(2); + } else { + $progressBar->minSecondsBetweenRedraws(0.1); + $progressBar->maxSecondsBetweenRedraws(0.5); + } + + return $progressBar; + } + + private function isCiDetected(): bool + { + if ($this->isCiDetected === null) { + $ciDetector = new CiDetector(); + $this->isCiDetected = $ciDetector->isCiDetected(); + } + + return $this->isCiDetected; + } +} diff --git a/src/Console/Style/SymfonyStyleFactory.php b/src/Console/Style/RectorConsoleOutputStyleFactory.php similarity index 84% rename from src/Console/Style/SymfonyStyleFactory.php rename to src/Console/Style/RectorConsoleOutputStyleFactory.php index e843dbeb581..547221def4f 100644 --- a/src/Console/Style/SymfonyStyleFactory.php +++ b/src/Console/Style/RectorConsoleOutputStyleFactory.php @@ -8,17 +8,16 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; use Symplify\PackageBuilder\Reflection\PrivatesCaller; -final class SymfonyStyleFactory +final class RectorConsoleOutputStyleFactory { public function __construct( private readonly PrivatesCaller $privatesCaller ) { } - public function create(): SymfonyStyle + public function create(): RectorConsoleOutputStyle { $argvInput = new ArgvInput(); $consoleOutput = new ConsoleOutput(); @@ -32,6 +31,6 @@ final class SymfonyStyleFactory $consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } - return new SymfonyStyle($argvInput, $consoleOutput); + return new RectorConsoleOutputStyle($argvInput, $consoleOutput); } }