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;
|
2018-02-24 21:24:57 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
/**
|
2018-02-24 21:24:57 +00:00
|
|
|
* @var ConsoleStyle
|
2017-10-22 14:31:29 +00:00
|
|
|
*/
|
2018-02-24 21:24:57 +00:00
|
|
|
private $consoleStyle;
|
2017-10-22 14:31:29 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-24 21:24:57 +00:00
|
|
|
* @var RectorNodeTraverser
|
2017-10-22 14:31:29 +00:00
|
|
|
*/
|
2018-02-24 21:24:57 +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;
|
2018-02-24 21:24:57 +00:00
|
|
|
$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()
|
|
|
|
);
|
|
|
|
|
2018-01-06 16:01:53 +00:00
|
|
|
$rectorClasses = array_map(function (RectorInterface $rector): string {
|
2017-12-28 04:10:28 +00:00
|
|
|
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);
|
2017-12-28 04:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $changedFiles
|
|
|
|
*/
|
|
|
|
public function reportChangedFiles(array $changedFiles): void
|
|
|
|
{
|
2018-01-06 23:09:22 +00:00
|
|
|
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-01-02 06:03:11 +00:00
|
|
|
/**
|
2018-02-08 15:51:16 +00:00
|
|
|
* @param FileDiff[] $fileDiffs
|
2018-01-02 06:03:11 +00:00
|
|
|
*/
|
2018-02-08 15:51:16 +00:00
|
|
|
public function reportFileDiffs(array $fileDiffs): void
|
2018-01-02 06:03:11 +00:00
|
|
|
{
|
2018-02-08 15:51:16 +00:00
|
|
|
if (count($fileDiffs) <= 0) {
|
2018-01-06 23:09:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-02 06:03:11 +00:00
|
|
|
$this->consoleStyle->title(sprintf(
|
|
|
|
'%d file%s with changes',
|
2018-02-08 15:51:16 +00:00
|
|
|
count($fileDiffs),
|
|
|
|
count($fileDiffs) === 1 ? '' : 's'
|
2018-01-02 06:03:11 +00:00
|
|
|
));
|
|
|
|
|
2018-01-06 20:10:35 +00:00
|
|
|
$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()));
|
2018-01-03 18:11:59 +00:00
|
|
|
$this->consoleStyle->newLine();
|
2018-02-08 15:51:16 +00:00
|
|
|
$this->consoleStyle->writeln($fileDiff->getDiff());
|
2018-01-03 18:11:59 +00:00
|
|
|
$this->consoleStyle->newLine();
|
2018-01-02 06:03:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-22 14:31:29 +00:00
|
|
|
}
|