rector/src/Console/Output/ProcessCommandReporter.php

96 lines
2.6 KiB
PHP
Raw Normal View History

2017-10-22 14:31:29 +00:00
<?php declare(strict_types=1);
namespace Rector\Console\Output;
2017-12-28 07:56:00 +00:00
use Rector\Console\ConsoleStyle;
2017-12-28 17:32:02 +00:00
use Rector\Contract\Rector\RectorInterface;
use Rector\NodeTraverser\RectorNodeTraverser;
2018-02-08 15:51:16 +00:00
use Rector\Reporting\FileDiff;
2018-06-27 23:25:07 +00:00
use Rector\YamlRector\YamlFileProcessor;
2017-10-22 14:31:29 +00:00
final class ProcessCommandReporter
{
/**
* @var ConsoleStyle
2017-10-22 14:31:29 +00:00
*/
private $consoleStyle;
2017-10-22 14:31:29 +00:00
/**
* @var RectorNodeTraverser
2017-10-22 14:31:29 +00:00
*/
private $rectorNodeTraverser;
2017-10-22 14:31:29 +00:00
2018-06-27 23:25:07 +00:00
/**
* @var YamlFileProcessor
*/
private $yamlFileProcessor;
public function __construct(
RectorNodeTraverser $rectorNodeTraverser,
ConsoleStyle $consoleStyle,
YamlFileProcessor $yamlFileProcessor
) {
2017-12-28 07:56:00 +00:00
$this->consoleStyle = $consoleStyle;
$this->rectorNodeTraverser = $rectorNodeTraverser;
2018-06-27 23:25:07 +00:00
$this->yamlFileProcessor = $yamlFileProcessor;
2017-10-22 14:31:29 +00:00
}
public function reportLoadedRectors(): void
{
2018-06-27 23:25:07 +00:00
$rectorCount = $this->rectorNodeTraverser->getRectorCount() + $this->yamlFileProcessor->getYamlRectorsCount();
$this->consoleStyle->title(sprintf('%d Loaded Rector%s', $rectorCount, $rectorCount === 1 ? '' : 's'));
2017-10-22 14:31:29 +00:00
2018-08-29 17:30:42 +00:00
$allRectors = array_merge(
$this->rectorNodeTraverser->getRectors() + $this->yamlFileProcessor->getYamlRectors()
);
$rectorClasses = array_map(function (RectorInterface $rector): string {
return get_class($rector);
2018-08-29 17:30:42 +00:00
}, $allRectors);
2018-06-27 23:25:07 +00:00
2018-08-29 17:30:42 +00:00
$this->consoleStyle->listing($rectorClasses);
}
/**
* @param string[] $changedFiles
*/
public function reportChangedFiles(array $changedFiles): void
{
if (count($changedFiles) <= 0) {
return;
}
2017-12-28 07:56:00 +00:00
$this->consoleStyle->title(sprintf(
2017-12-28 17:27:32 +00:00
'%d Changed file%s',
2017-12-28 05:02:04 +00:00
count($changedFiles),
count($changedFiles) === 1 ? '' : 's'
));
2017-12-28 07:56:00 +00:00
$this->consoleStyle->listing($changedFiles);
2017-10-22 14:31:29 +00:00
}
2017-12-20 01:12:15 +00:00
/**
2018-02-08 15:51:16 +00:00
* @param FileDiff[] $fileDiffs
*/
2018-02-08 15:51:16 +00:00
public function reportFileDiffs(array $fileDiffs): void
{
2018-02-08 15:51:16 +00:00
if (count($fileDiffs) <= 0) {
return;
}
$this->consoleStyle->title(sprintf(
'%d file%s with changes',
2018-02-08 15:51:16 +00:00
count($fileDiffs),
count($fileDiffs) === 1 ? '' : 's'
));
$i = 0;
2018-02-08 15:51:16 +00:00
foreach ($fileDiffs as $fileDiff) {
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $fileDiff->getFile()));
$this->consoleStyle->newLine();
2018-02-08 15:51:16 +00:00
$this->consoleStyle->writeln($fileDiff->getDiff());
$this->consoleStyle->newLine();
}
}
2017-10-22 14:31:29 +00:00
}