Skip to content

Commit

Permalink
move step count to own method (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Nov 1, 2020
1 parent 42fcff9 commit 7ce55d6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Application/RectorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Configuration\Configuration;
use Rector\Core\EventDispatcher\Event\AfterProcessEvent;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Testing\Application\EnabledRectorsProvider;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -92,6 +93,11 @@ final class RectorApplication
*/
private $eventDispatcher;

/**
* @var PrivatesAccessor
*/
private $privatesAccessor;

public function __construct(
Configuration $configuration,
EnabledRectorsProvider $enabledRectorsProvider,
Expand All @@ -101,7 +107,8 @@ public function __construct(
NodeScopeResolver $nodeScopeResolver,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
SymfonyStyle $symfonyStyle
SymfonyStyle $symfonyStyle,
PrivatesAccessor $privatesAccessor
) {
$this->symfonyStyle = $symfonyStyle;
$this->errorAndDiffCollector = $errorAndDiffCollector;
Expand All @@ -112,6 +119,7 @@ public function __construct(
$this->enabledRectorsProvider = $enabledRectorsProvider;
$this->nodeScopeResolver = $nodeScopeResolver;
$this->eventDispatcher = $eventDispatcher;
$this->privatesAccessor = $privatesAccessor;
}

/**
Expand Down Expand Up @@ -176,8 +184,7 @@ private function prepareProgressBar(int $fileCount): void
return;
}

$this->symfonyStyle->progressStart($fileCount * self::PROGRESS_BAR_STEP_MULTIPLIER);
$this->configureStepCount();
$this->configureStepCount($fileCount);
}

/**
Expand Down Expand Up @@ -259,12 +266,15 @@ private function printFileInfo(SmartFileInfo $fileInfo): void
/**
* This prevent CI report flood with 1 file = 1 line in progress bar
*/
private function configureStepCount(): void
private function configureStepCount(int $fileCount): void
{
$privatesAccessor = new PrivatesAccessor();
$this->symfonyStyle->progressStart($fileCount * self::PROGRESS_BAR_STEP_MULTIPLIER);

$progressBar = $this->privatesAccessor->getPrivateProperty($this->symfonyStyle, 'progressBar');
if ($progressBar instanceof ProgressBar) {
throw new ShouldNotHappenException();
}

/** @var ProgressBar $progressBar */
$progressBar = $privatesAccessor->getPrivateProperty($this->symfonyStyle, 'progressBar');
if ($progressBar->getMaxSteps() < 40) {
return;
}
Expand Down

0 comments on commit 7ce55d6

Please sign in to comment.