Skip to content

Commit

Permalink
Improve EmptyConfigurableRectorChecker to report missed rule instantly (
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 28, 2021
1 parent 0a704af commit 849ed2f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/Validation/EmptyConfigurableRectorChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

namespace Rector\Core\Validation;

use Nette\Utils\Strings;
use function count;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
use Symfony\Component\Console\Style\SymfonyStyle;

final class EmptyConfigurableRectorChecker
{
/**
* @var string
*/
private const SOLUTION_MESSAGE = 'Do you want to run them? Ensure configure them in your `rector.php`.';

public function __construct(
private EmptyConfigurableRectorCollector $emptyConfigurableRectorCollector,
private SymfonyStyle $symfonyStyle
Expand All @@ -28,14 +23,17 @@ public function __construct(
public function check(array $rectors): void
{
$emptyConfigurableRectors = $this->emptyConfigurableRectorCollector->resolveEmptyConfigurable($rectors);

if ($emptyConfigurableRectors === []) {
return;
}

$this->reportWarningMessage($emptyConfigurableRectors);
$this->reportEmptyConfigurableMessage($emptyConfigurableRectors);
$this->symfonyStyle->note(self::SOLUTION_MESSAGE);

$solutionMessage = sprintf(
'Do you want to run them?%sConfigure them in `rector.php` with ...->call("configure", ...);',
PHP_EOL
);
$this->symfonyStyle->note($solutionMessage);

if (! $this->symfonyStyle->isVerbose()) {
// ensure there is new line after progress bar and report : "[OK] Rector is done!" with add a space
Expand All @@ -49,27 +47,16 @@ public function check(array $rectors): void
private function reportWarningMessage(array $emptyConfigurableRectors): void
{
$warningMessage = sprintf(
'Your project contains %d configurable rector rules that skipped as need to be configured to run, use -vvv for detailed info.',
'Your project contains %d configurable rector rules that are skipped as need to be configured to run.',
count($emptyConfigurableRectors)
);

$this->symfonyStyle->warning($warningMessage);
}

/**
* @param RectorInterface[] $emptyConfigurableRectors
*/
private function reportEmptyConfigurableMessage(array $emptyConfigurableRectors): void
{
if (! $this->symfonyStyle->isVerbose()) {
return;
}

foreach ($emptyConfigurableRectors as $emptyConfigurableRector) {
$shortRectorClass = Strings::after($emptyConfigurableRector::class, '\\', -1);

$rectorMessage = ' * ' . $shortRectorClass;
$this->symfonyStyle->writeln($rectorMessage);
$this->symfonyStyle->writeln(' * ' . $emptyConfigurableRector::class);
}

// to take time to absorb it
sleep(3);
}
}

0 comments on commit 849ed2f

Please sign in to comment.