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;
|
2017-10-22 14:31:29 +00:00
|
|
|
use Rector\Rector\RectorCollector;
|
|
|
|
|
|
|
|
final class ProcessCommandReporter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var RectorCollector
|
|
|
|
*/
|
|
|
|
private $rectorCollector;
|
|
|
|
|
|
|
|
/**
|
2017-12-28 07:56:00 +00:00
|
|
|
* @var ConsoleStyle
|
2017-10-22 14:31:29 +00:00
|
|
|
*/
|
2017-12-28 07:56:00 +00:00
|
|
|
private $consoleStyle;
|
2017-10-22 14:31:29 +00:00
|
|
|
|
2017-12-28 07:56:00 +00:00
|
|
|
public function __construct(RectorCollector $rectorCollector, ConsoleStyle $consoleStyle)
|
2017-12-20 01:12:15 +00:00
|
|
|
{
|
2017-10-22 14:31:29 +00:00
|
|
|
$this->rectorCollector = $rectorCollector;
|
2017-12-28 07:56:00 +00:00
|
|
|
$this->consoleStyle = $consoleStyle;
|
2017-10-22 14:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function reportLoadedRectors(): void
|
|
|
|
{
|
2017-12-28 07:56:00 +00:00
|
|
|
$this->consoleStyle->title(sprintf(
|
2017-10-22 14:31:29 +00:00
|
|
|
'%d Loaded Rector%s',
|
|
|
|
$this->rectorCollector->getRectorCount(),
|
2017-12-28 05:02:04 +00:00
|
|
|
$this->rectorCollector->getRectorCount() === 1 ? '' : 's'
|
2017-10-22 14:31:29 +00:00
|
|
|
));
|
|
|
|
|
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-01-06 16:01:53 +00:00
|
|
|
}, $this->rectorCollector->getRectors());
|
|
|
|
|
|
|
|
$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
|
|
|
/**
|
|
|
|
* @param string[][] $diffFiles
|
|
|
|
*/
|
|
|
|
public function reportDiffFiles(array $diffFiles): void
|
|
|
|
{
|
2018-01-06 23:09:22 +00:00
|
|
|
if (count($diffFiles) <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-02 06:03:11 +00:00
|
|
|
$this->consoleStyle->title(sprintf(
|
|
|
|
'%d file%s with changes',
|
|
|
|
count($diffFiles),
|
|
|
|
count($diffFiles) === 1 ? '' : 's'
|
|
|
|
));
|
|
|
|
|
2018-01-06 20:10:35 +00:00
|
|
|
$i = 0;
|
2018-01-02 06:03:11 +00:00
|
|
|
foreach ($diffFiles as $diffFile) {
|
2018-01-06 20:10:35 +00:00
|
|
|
$this->consoleStyle->writeln(sprintf('<options=bold>%d) %s</>', ++$i, $diffFile['file']));
|
2018-01-03 18:11:59 +00:00
|
|
|
$this->consoleStyle->newLine();
|
2018-01-02 06:03:11 +00:00
|
|
|
$this->consoleStyle->writeln($diffFile['diff']);
|
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
|
|
|
}
|