rector/src/Console/Output/ProcessCommandReporter.php

68 lines
1.7 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;
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
));
2017-12-20 01:12:15 +00:00
$rectorList = $this->sortByClassName($this->rectorCollector->getRectors());
2017-12-28 17:32:02 +00:00
$this->consoleStyle->listing(array_map(function (RectorInterface $rector): string {
return get_class($rector);
}, $rectorList));
}
/**
* @param string[] $changedFiles
*/
public function reportChangedFiles(array $changedFiles): void
{
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
/**
* @param object[] $objects
* @return object[]
*/
private function sortByClassName(array $objects): array
{
usort($objects, function ($first, $second): int {
return get_class($first) <=> get_class($second);
});
return $objects;
}
2017-10-22 14:31:29 +00:00
}