Skip to content
Draft
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
17 changes: 12 additions & 5 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

final class ProcessCommand extends Command
{
private SymfonyStyle $errorSymfonyStyle;

public function __construct(
private readonly AdditionalAutoloader $additionalAutoloader,
private readonly ChangedFilesDetector $changedFilesDetector,
Expand Down Expand Up @@ -82,6 +85,10 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->errorSymfonyStyle = $output instanceof ConsoleOutputInterface
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is probably a better way to do this with the Laravel Container... But I'm not familiar with it, and I could not really find it, so meanwhile this works.

? new SymfonyStyle($input, $output->getErrorOutput())
: $this->symfonyStyle;

// missing config? add it :)
if (! $this->configInitializer->areSomeRectorsLoaded()) {
$this->configInitializer->createConfig(getcwd());
Expand Down Expand Up @@ -109,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// 0. warn about skipped rules that are deprecated
if ($this->skippedClassResolver->resolveDeprecatedSkippedClasses() !== []) {
$this->symfonyStyle->warning(sprintf(
$this->errorSymfonyStyle->warning(sprintf(
'These rules are skipped, but are deprecated. Most likely you do not need to skip them anymore as not part of any set and remove them: %s* %s',
"\n\n",
implode(' * ', $this->skippedClassResolver->resolveDeprecatedSkippedClasses()) . "\n"
Expand All @@ -119,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// 1. warn about rules registered in both withRules() and sets to avoid bloated rector.php configs
$setAndRulesDuplicatedRegistrations = $configuration->getBothSetAndRulesDuplicatedRegistrations();
if ($setAndRulesDuplicatedRegistrations !== []) {
$this->symfonyStyle->warning(sprintf(
$this->errorSymfonyStyle->warning(sprintf(
'These rules are registered in both sets and "withRules()". Remove them from "withRules()" to avoid duplications: %s* %s',
"\n\n",
implode(' * ', $setAndRulesDuplicatedRegistrations) . "\n"
Expand Down Expand Up @@ -246,8 +253,8 @@ private function reportLoadedComposerBasedSets(): void
return;
}

$this->symfonyStyle->writeln('[info] Sets loaded based on installed packages:');
$this->symfonyStyle->listing($composerBasedSets);
$this->errorSymfonyStyle->writeln('[info] Sets loaded based on installed packages:');
$this->errorSymfonyStyle->listing($composerBasedSets);
}

private function reportLevelOverflow(LevelOverflow $levelOverflow): void
Expand All @@ -257,7 +264,7 @@ private function reportLevelOverflow(LevelOverflow $levelOverflow): void
$levelOverflow->getSuggestedRuleset()
) : sprintf('->withSets(SetList::%s)', $levelOverflow->getSuggestedSetListConstant());

$this->symfonyStyle->warning(sprintf(
$this->errorSymfonyStyle->warning(sprintf(
'The "->%s()" level contains only %d rules, but you set level to %d.%sYou are using the full set now! Time to switch to more efficient "%s".',
$levelOverflow->getConfigurationName(),
$levelOverflow->getRuleCount(),
Expand Down