mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
refactor reporting runner to event subscriber
This commit is contained in:
parent
ebb8e882fb
commit
21f67be9c3
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Extension\Contract;
|
||||
|
||||
interface ReportingExtensionInterface
|
||||
{
|
||||
public function run(): void;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Extension\Runner;
|
||||
|
||||
use Rector\Extension\Contract\ReportingExtensionInterface;
|
||||
|
||||
/**
|
||||
* @todo refactor to event system
|
||||
*/
|
||||
final class ReportingExtensionRunner
|
||||
{
|
||||
/**
|
||||
* @var ReportingExtensionInterface[]
|
||||
*/
|
||||
private $reportingExtensions = [];
|
||||
|
||||
/**
|
||||
* @param ReportingExtensionInterface[] $reportingExtensions
|
||||
*/
|
||||
public function __construct(array $reportingExtensions = [])
|
||||
{
|
||||
$this->reportingExtensions = $reportingExtensions;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
foreach ($this->reportingExtensions as $reportingExtension) {
|
||||
$reportingExtension->run();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,16 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Reporting\Extension;
|
||||
namespace Rector\Reporting\EventSibscriber;
|
||||
|
||||
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
|
||||
use Rector\Core\Configuration\Configuration;
|
||||
use Rector\Extension\Contract\ReportingExtensionInterface;
|
||||
use Rector\Core\EventDispatcher\Event\AfterReportEvent;
|
||||
use Rector\Reporting\DataCollector\ReportCollector;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
final class GenericReportMessageReportingExtension implements ReportingExtensionInterface
|
||||
final class PrintReportCollectorEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ReportCollector
|
||||
@ -37,7 +38,15 @@ final class GenericReportMessageReportingExtension implements ReportingExtension
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [AfterReportEvent::class => 'printReportCollector'];
|
||||
}
|
||||
|
||||
public function printReportCollector(): void
|
||||
{
|
||||
if ($this->shouldSkip()) {
|
||||
return;
|
@ -13,17 +13,18 @@ use Rector\Core\Autoloading\AdditionalAutoloader;
|
||||
use Rector\Core\Configuration\Configuration;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Console\Output\OutputFormatterCollector;
|
||||
use Rector\Core\EventDispatcher\Event\AfterReportEvent;
|
||||
use Rector\Core\FileSystem\FilesFinder;
|
||||
use Rector\Core\Guard\RectorGuard;
|
||||
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
|
||||
use Rector\Core\Stubs\StubLoader;
|
||||
use Rector\Core\Yaml\YamlProcessor;
|
||||
use Rector\Extension\Runner\ReportingExtensionRunner;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||
use Symplify\PackageBuilder\Console\ShellCode;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
@ -65,11 +66,6 @@ final class ProcessCommand extends AbstractCommand
|
||||
*/
|
||||
private $outputFormatterCollector;
|
||||
|
||||
/**
|
||||
* @var ReportingExtensionRunner
|
||||
*/
|
||||
private $reportingExtensionRunner;
|
||||
|
||||
/**
|
||||
* @var RectorNodeTraverser
|
||||
*/
|
||||
@ -100,6 +96,11 @@ final class ProcessCommand extends AbstractCommand
|
||||
*/
|
||||
private $symfonyStyle;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
public function __construct(
|
||||
FilesFinder $phpFilesFinder,
|
||||
AdditionalAutoloader $additionalAutoloader,
|
||||
@ -108,13 +109,13 @@ final class ProcessCommand extends AbstractCommand
|
||||
Configuration $configuration,
|
||||
RectorApplication $rectorApplication,
|
||||
OutputFormatterCollector $outputFormatterCollector,
|
||||
ReportingExtensionRunner $reportingExtensionRunner,
|
||||
RectorNodeTraverser $rectorNodeTraverser,
|
||||
StubLoader $stubLoader,
|
||||
YamlProcessor $yamlProcessor,
|
||||
ChangedFilesDetector $changedFilesDetector,
|
||||
UnchangedFilesFilter $unchangedFilesFilter,
|
||||
SymfonyStyle $symfonyStyle
|
||||
SymfonyStyle $symfonyStyle,
|
||||
EventDispatcherInterface $eventDispatcher
|
||||
) {
|
||||
$this->filesFinder = $phpFilesFinder;
|
||||
$this->additionalAutoloader = $additionalAutoloader;
|
||||
@ -123,7 +124,6 @@ final class ProcessCommand extends AbstractCommand
|
||||
$this->configuration = $configuration;
|
||||
$this->rectorApplication = $rectorApplication;
|
||||
$this->outputFormatterCollector = $outputFormatterCollector;
|
||||
$this->reportingExtensionRunner = $reportingExtensionRunner;
|
||||
$this->rectorNodeTraverser = $rectorNodeTraverser;
|
||||
$this->stubLoader = $stubLoader;
|
||||
$this->yamlProcessor = $yamlProcessor;
|
||||
@ -133,6 +133,7 @@ final class ProcessCommand extends AbstractCommand
|
||||
|
||||
$this->changedFilesDetector = $changedFilesDetector;
|
||||
$this->symfonyStyle = $symfonyStyle;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
@ -234,7 +235,7 @@ final class ProcessCommand extends AbstractCommand
|
||||
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
|
||||
$outputFormatter->report($this->errorAndDiffCollector);
|
||||
|
||||
$this->reportingExtensionRunner->run();
|
||||
$this->eventDispatcher->dispatch(new AfterReportEvent());
|
||||
|
||||
// invalidate affected files
|
||||
$this->invalidateAffectedCacheFiles();
|
||||
|
11
src/EventDispatcher/Event/AfterReportEvent.php
Normal file
11
src/EventDispatcher/Event/AfterReportEvent.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\EventDispatcher\Event;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
final class AfterReportEvent extends Event
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user