Skip to content

Commit

Permalink
Add option --no-progress to command finalize-classes (#72)
Browse files Browse the repository at this point in the history
This makes the output more readable when the command is run in CI.
Tools such as Rector and PHPStan also implement this.
  • Loading branch information
spawnia authored Jan 16, 2025
1 parent 4024097 commit bcbf31d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Do no change anything, only list classes about to be finalized'
);

$this->addOption(
'no-progress',
null,
InputOption::VALUE_NONE,
'Do not show progress bar, only results'
);
}

/**
Expand All @@ -82,12 +89,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$skippedFiles = $input->getOption('skip-file');
$phpFileInfos = PhpFilesFinder::find($paths, $skippedFiles);

// double to count for both parent and entity resolver
$stepRatio = $areMockedSkipped ? 3 : 2;
$noProgress = (bool) $input->getOption('no-progress');
if (! $noProgress) {
// double to count for both parent and entity resolver
$stepRatio = $areMockedSkipped ? 3 : 2;

$this->symfonyStyle->progressStart($stepRatio * count($phpFileInfos));
$this->symfonyStyle->progressStart($stepRatio * count($phpFileInfos));
}

$progressClosure = function () use ($noProgress): void {
if ($noProgress) {
return;
}

$progressClosure = function (): void {
$this->symfonyStyle->progressAdvance();
};

Expand All @@ -96,7 +110,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$mockedClassNames = $areMockedSkipped ? $this->mockedClassResolver->resolve($paths, $progressClosure) : [];

$this->symfonyStyle->progressFinish();
if (! $noProgress) {
$this->symfonyStyle->progressFinish();
}

$this->symfonyStyle->writeln(sprintf(
'Found %d parent and %d entity classes',
Expand Down

0 comments on commit bcbf31d

Please sign in to comment.