Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/Application/ErrorAndDiffCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public function getFileDiffs(): array
return $this->fileDiffs;
}

public function getFileDiffsCount(): int
{
return count($this->getFileDiffs());
}

public function addAutoloadError(AnalysedCodeException $analysedCodeException, SmartFileInfo $fileInfo): void
{
$message = $this->exceptionCorrector->getAutoloadExceptionMessageAndAddLocation($analysedCodeException);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

// inverse error code for CI dry-run
if ($this->configuration->isDryRun() && count($this->errorAndDiffCollector->getFileDiffs())) {
if ($this->configuration->isDryRun() && $this->errorAndDiffCollector->getFileDiffsCount()) {
return Shell::CODE_ERROR;
}

Expand Down
31 changes: 25 additions & 6 deletions src/Console/Output/ConsoleOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use Rector\Application\ErrorAndDiffCollector;
use Rector\Configuration\Configuration;
use Rector\Contract\Console\Output\OutputFormatterInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Printer\BetterStandardPrinter;
Expand All @@ -31,10 +32,19 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
*/
private $betterStandardPrinter;

public function __construct(SymfonyStyle $symfonyStyle, BetterStandardPrinter $betterStandardPrinter)
{
/**
* @var Configuration
*/
private $configuration;

public function __construct(
SymfonyStyle $symfonyStyle,
BetterStandardPrinter $betterStandardPrinter,
Configuration $configuration
) {
$this->symfonyStyle = $symfonyStyle;
$this->betterStandardPrinter = $betterStandardPrinter;
$this->configuration = $configuration;
}

public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
Expand All @@ -47,10 +57,19 @@ public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
return;
}

$this->symfonyStyle->success(sprintf(
'Rector is done! %d changed files',
count($errorAndDiffCollector->getFileDiffs()) + $errorAndDiffCollector->getRemovedAndAddedFilesCount()
));
$changeCount = $errorAndDiffCollector->getFileDiffsCount()
+ $errorAndDiffCollector->getRemovedAndAddedFilesCount();
$message = 'Rector is done!';
if ($changeCount > 0) {
$message .= sprintf(
' %d file%s %s.',
$changeCount,
$changeCount > 1 ? 's' : '',
$this->configuration->isDryRun() ? 'would have changed (dry-run)' : 'have been changed'
);
}

$this->symfonyStyle->success($message);
}

public function getName(): string
Expand Down
5 changes: 2 additions & 3 deletions src/Console/Output/JsonOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,19 @@ public function getName(): string

public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
{
$fileDiffs = $errorAndDiffCollector->getFileDiffs();

$errorsArray = [
'meta' => [
'version' => $this->configuration->getPrettyVersion(),
'config' => $this->configuration->getConfigFilePath(),
],
'totals' => [
'changed_files' => count($fileDiffs),
'changed_files' => $errorAndDiffCollector->getFileDiffsCount(),
'removed_and_added_files_count' => $errorAndDiffCollector->getRemovedAndAddedFilesCount(),
'removed_node_count' => $errorAndDiffCollector->getRemovedNodeCount(),
],
];

$fileDiffs = $errorAndDiffCollector->getFileDiffs();
ksort($fileDiffs);
foreach ($fileDiffs as $fileDiff) {
$relativeFilePath = $fileDiff->getRelativeFilePath();
Expand Down