Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve EmptyConfigurableRectorChecker to report missed rule instantly #1095

Merged
merged 3 commits into from
Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}