Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"nette/utils": "^2.5|^3.0",
"nikic/php-parser": "^4.2.2",
"phpstan/phpdoc-parser": "^0.3.5",
"phpstan/phpstan": "^0.11.10",
"phpstan/phpstan": "^0.11.13",
"phpstan/phpstan-phpunit": "^0.11.2",
"sebastian/diff": "^3.0",
"symfony/console": "^3.4|^4.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/NodeTypeResolver/src/PHPStan/Scope/ScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\Analyser\ScopeFactory as PHPStanScopeFactory;
use PHPStan\Analyser\TypeSpecifier;
use PHPStan\Broker\Broker;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use Rector\PhpParser\Printer\BetterStandardPrinter;

final class ScopeFactory
Expand Down Expand Up @@ -50,6 +51,7 @@ public function createFromFile(string $filePath): Scope
$this->broker,
$this->betterStandardPrinter,
$this->typeSpecifier,
new PropertyReflectionFinder(),
ScopeContext::create($filePath)
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Application/RectorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Configuration\Configuration;
use Rector\Extension\RectorFinishExtensionRunner;
use Rector\Extension\FinishingExtensionRunner;
use Rector\FileSystemRector\FileSystemFileProcessor;
use Rector\Testing\Application\EnabledRectorsProvider;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -76,9 +76,9 @@ final class RectorApplication
private $nodeScopeResolver;

/**
* @var RectorFinishExtensionRunner
* @var FinishingExtensionRunner
*/
private $rectorFinishExtensionRunner;
private $finishingExtensionRunner;

public function __construct(
SymfonyStyle $symfonyStyle,
Expand All @@ -90,7 +90,7 @@ public function __construct(
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
NodeScopeResolver $nodeScopeResolver,
RectorFinishExtensionRunner $rectorFinishExtensionRunner
FinishingExtensionRunner $finishingExtensionRunner
) {
$this->symfonyStyle = $symfonyStyle;
$this->fileSystemFileProcessor = $fileSystemFileProcessor;
Expand All @@ -101,7 +101,7 @@ public function __construct(
$this->removedAndAddedFilesProcessor = $removedAndAddedFilesProcessor;
$this->enabledRectorsProvider = $enabledRectorsProvider;
$this->nodeScopeResolver = $nodeScopeResolver;
$this->rectorFinishExtensionRunner = $rectorFinishExtensionRunner;
$this->finishingExtensionRunner = $finishingExtensionRunner;
}

/**
Expand Down Expand Up @@ -156,8 +156,8 @@ public function runOnFileInfos(array $fileInfos): void
// 4. remove and add files
$this->removedAndAddedFilesProcessor->run();

// 5. on finish
$this->rectorFinishExtensionRunner->run();
// 5. extensions on finish
$this->finishingExtensionRunner->run();
}

private function tryCatchWrapper(SmartFileInfo $smartFileInfo, callable $callback, string $phase): void
Expand Down
10 changes: 10 additions & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\Console\Output\ConsoleOutputFormatter;
use Rector\Console\Output\OutputFormatterCollector;
use Rector\Console\Shell;
use Rector\Extension\ReportingExtensionRunner;
use Rector\FileSystem\FilesFinder;
use Rector\Guard\RectorGuard;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -60,6 +61,11 @@ final class ProcessCommand extends AbstractCommand
*/
private $outputFormatterCollector;

/**
* @var ReportingExtensionRunner
*/
private $reportingExtensionRunner;

/**
* @param string[] $fileExtensions
*/
Expand All @@ -71,6 +77,7 @@ public function __construct(
Configuration $configuration,
RectorApplication $rectorApplication,
OutputFormatterCollector $outputFormatterCollector,
ReportingExtensionRunner $reportingExtensionRunner,
array $fileExtensions
) {
$this->filesFinder = $phpFilesFinder;
Expand All @@ -81,6 +88,7 @@ public function __construct(
$this->rectorApplication = $rectorApplication;
$this->fileExtensions = $fileExtensions;
$this->outputFormatterCollector = $outputFormatterCollector;
$this->reportingExtensionRunner = $reportingExtensionRunner;

parent::__construct();
}
Expand Down Expand Up @@ -145,6 +153,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
$outputFormatter->report($this->errorAndDiffCollector);

$this->reportingExtensionRunner->run();

// some errors were found → fail
if ($this->errorAndDiffCollector->getErrors() !== []) {
return Shell::CODE_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Contract\Extension;

interface RectorFinishExtensionInterface
interface FinishingExtensionInterface
{
public function run(): void;
}
8 changes: 8 additions & 0 deletions src/Contract/Extension/ReportingExtensionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Rector\Contract\Extension;

interface ReportingExtensionInterface
{
public function run(): void;
}
28 changes: 28 additions & 0 deletions src/Extension/FinishingExtensionRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace Rector\Extension;

use Rector\Contract\Extension\FinishingExtensionInterface;

final class FinishingExtensionRunner
{
/**
* @var FinishingExtensionInterface[]
*/
private $finishingExtensions = [];

/**
* @param FinishingExtensionInterface[] $finishingExtensions
*/
public function __construct(array $finishingExtensions = [])
{
$this->finishingExtensions = $finishingExtensions;
}

public function run(): void
{
foreach ($this->finishingExtensions as $finishingExtension) {
$finishingExtension->run();
}
}
}
28 changes: 0 additions & 28 deletions src/Extension/RectorFinishExtensionRunner.php

This file was deleted.

28 changes: 28 additions & 0 deletions src/Extension/ReportingExtensionRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace Rector\Extension;

use Rector\Contract\Extension\ReportingExtensionInterface;

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();
}
}
}