mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
unite OutputFormatterInterface to report() method
This commit is contained in:
parent
8ca511a8e2
commit
d869606655
@ -164,10 +164,9 @@ final class ProcessCommand extends AbstractCommand
|
||||
$outputFormat = (string) $input->getOption(Option::OPTION_OUTPUT_FORMAT);
|
||||
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
|
||||
|
||||
$outputFormatter->reportFileDiffs($this->errorAndDiffCollector->getFileDiffs());
|
||||
$outputFormatter->report($this->errorAndDiffCollector);
|
||||
|
||||
if ($this->errorAndDiffCollector->getErrors() !== []) {
|
||||
$outputFormatter->reportErrors($this->errorAndDiffCollector->getErrors());
|
||||
return Shell::CODE_ERROR;
|
||||
}
|
||||
|
||||
@ -182,6 +181,7 @@ final class ProcessCommand extends AbstractCommand
|
||||
) + $this->errorAndDiffCollector->getRemovedAndAddedFilesCount()
|
||||
));
|
||||
|
||||
// inverse error code for CI dry-run
|
||||
if ($this->configuration->isDryRun() && count($this->errorAndDiffCollector->getFileDiffs())) {
|
||||
return Shell::CODE_ERROR;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Rector\Console\Output;
|
||||
|
||||
use Rector\Application\Error;
|
||||
use Rector\Application\ErrorAndDiffCollector;
|
||||
use Rector\Contract\Console\Output\OutputFormatterInterface;
|
||||
use Rector\Reporting\FileDiff;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
@ -24,6 +25,12 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
}
|
||||
|
||||
public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
|
||||
{
|
||||
$this->reportFileDiffs($errorAndDiffCollector->getFileDiffs());
|
||||
$this->reportErrors($errorAndDiffCollector->getErrors());
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return self::NAME;
|
||||
@ -32,7 +39,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
|
||||
/**
|
||||
* @param FileDiff[] $fileDiffs
|
||||
*/
|
||||
public function reportFileDiffs(array $fileDiffs): void
|
||||
private function reportFileDiffs(array $fileDiffs): void
|
||||
{
|
||||
if (count($fileDiffs) <= 0) {
|
||||
return;
|
||||
@ -64,7 +71,7 @@ final class ConsoleOutputFormatter implements OutputFormatterInterface
|
||||
/**
|
||||
* @param Error[] $errors
|
||||
*/
|
||||
public function reportErrors(array $errors): void
|
||||
private function reportErrors(array $errors): void
|
||||
{
|
||||
foreach ($errors as $error) {
|
||||
$message = sprintf(
|
||||
|
@ -3,9 +3,8 @@
|
||||
namespace Rector\Console\Output;
|
||||
|
||||
use Nette\Utils\Json;
|
||||
use Rector\Application\Error;
|
||||
use Rector\Application\ErrorAndDiffCollector;
|
||||
use Rector\Contract\Console\Output\OutputFormatterInterface;
|
||||
use Rector\Reporting\FileDiff;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
final class JsonOutputFormatter implements OutputFormatterInterface
|
||||
@ -25,11 +24,10 @@ final class JsonOutputFormatter implements OutputFormatterInterface
|
||||
return 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FileDiff[] $fileDiffs
|
||||
*/
|
||||
public function reportFileDiffs(array $fileDiffs): void
|
||||
public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
|
||||
{
|
||||
$fileDiffs = $errorAndDiffCollector->getFileDiffs();
|
||||
|
||||
$errorsArray = [];
|
||||
$errorsArray['totals']['changed_files'] = count($fileDiffs);
|
||||
|
||||
@ -43,17 +41,7 @@ final class JsonOutputFormatter implements OutputFormatterInterface
|
||||
];
|
||||
}
|
||||
|
||||
$json = Json::encode($errorsArray, Json::PRETTY);
|
||||
|
||||
$this->symfonyStyle->writeln($json);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Error[] $errors
|
||||
*/
|
||||
public function reportErrors(array $errors): void
|
||||
{
|
||||
$errorsArray = [];
|
||||
$errors = $errorAndDiffCollector->getErrors();
|
||||
$errorsArray['totals']['errors'] = count($errors);
|
||||
|
||||
foreach ($errors as $error) {
|
||||
|
@ -2,20 +2,11 @@
|
||||
|
||||
namespace Rector\Contract\Console\Output;
|
||||
|
||||
use Rector\Application\Error;
|
||||
use Rector\Reporting\FileDiff;
|
||||
use Rector\Application\ErrorAndDiffCollector;
|
||||
|
||||
interface OutputFormatterInterface
|
||||
{
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* @param FileDiff[] $fileDiffs
|
||||
*/
|
||||
public function reportFileDiffs(array $fileDiffs): void;
|
||||
|
||||
/**
|
||||
* @param Error[] $errors
|
||||
*/
|
||||
public function reportErrors(array $errors): void;
|
||||
public function report(ErrorAndDiffCollector $errorAndDiffCollector): void;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user