droping events (#4865)

* drop unused ReportCollector and releted avain chains

* update fixed comma trail downgrade in php-parser

* add post runner interface

* [CodingStyle] Enabe post-inc-dec

* [ci-review] Rector Rectify

* test ci

* bump phpunit

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2020-12-12 15:58:47 +01:00 committed by GitHub
parent 184cf7ca85
commit f197e25793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 89 additions and 354 deletions

View File

@ -18,10 +18,10 @@
"doctrine/inflector": "^2.0",
"jean85/pretty-package-versions": "^1.5.1",
"nette/robot-loader": "^3.2",
"nette/utils": "^3.1",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.10.3",
"phpstan/phpdoc-parser": "^0.4.9",
"phpstan/phpstan": "^0.12.59",
"phpstan/phpstan": "^0.12.60",
"phpstan/phpstan-phpunit": "^0.12.16",
"psr/simple-cache": "^1.0",
"sebastian/diff": "^4.0",
@ -30,15 +30,15 @@
"symfony/dependency-injection": "^4.4.8|^5.1",
"symfony/finder": "^4.4.8|^5.1",
"symfony/http-kernel": "^4.4.8|^5.1",
"symplify/autowire-array-parameter": "^9.0.5",
"symplify/skipper": "^9.0.5",
"symplify/package-builder": "^9.0.5",
"symplify/simple-php-doc-parser": "^9.0.5",
"symplify/smart-file-system": "^9.0.5",
"symplify/rule-doc-generator": "^9.0.5",
"symplify/set-config-resolver": "^9.0.5",
"symplify/console-color-diff": "^9.0.5",
"symplify/symfony-php-config": "^9.0.5",
"symplify/autowire-array-parameter": "^9.0.6",
"symplify/skipper": "^9.0.6",
"symplify/package-builder": "^9.0.6",
"symplify/simple-php-doc-parser": "^9.0.6",
"symplify/smart-file-system": "^9.0.6",
"symplify/rule-doc-generator": "^9.0.6",
"symplify/set-config-resolver": "^9.0.6",
"symplify/console-color-diff": "^9.0.6",
"symplify/symfony-php-config": "^9.0.6",
"webmozart/assert": "^1.9"
},
"require-dev": {
@ -48,14 +48,14 @@
"nette/forms": "^3.0",
"ocramius/package-versions": "^1.9",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/phpunit": "^8.5|^9.2",
"psr/event-dispatcher": "^1.0",
"symplify/changelog-linker": "^9.0.5",
"symplify/easy-coding-standard": "^9.0.5",
"symplify/coding-standard": "^9.0.5",
"symplify/easy-testing": "^9.0.5",
"symplify/phpstan-extensions": "^9.0.5",
"symplify/phpstan-rules": "dev-master",
"phpunit/phpunit": "^9.5",
"sebastian/diff": "^4.0.4",
"symplify/changelog-linker": "^9.0.6",
"symplify/easy-coding-standard": "^9.0.6",
"symplify/coding-standard": "^9.0.6",
"symplify/easy-testing": "^9.0.6",
"symplify/phpstan-extensions": "^9.0.6",
"symplify/phpstan-rules": "^9.0.6",
"tracy/tracy": "^2.7"
},
"replace": {
@ -143,7 +143,6 @@
"Rector\\RectorGenerator\\": "packages/rector-generator/src",
"Rector\\RemovingStatic\\": "rules/removing-static/src",
"Rector\\Renaming\\": "rules/renaming/src",
"Rector\\Reporting\\": "packages/reporting/src",
"Rector\\Restoration\\": "rules/restoration/src",
"Rector\\SOLID\\": "rules/solid/src",
"Rector\\Sensio\\": "rules/sensio/src",

View File

@ -13,7 +13,6 @@ use PhpParser\ParserFactory;
use Rector\Core\Bootstrap\NoRectorsLoadedReporter;
use Rector\Core\Configuration\RectorClassesProvider;
use Rector\Core\Console\ConsoleApplication;
use Rector\Core\EventDispatcher\AutowiredEventDispatcher;
use Rector\Core\PhpParser\Parser\NikicPhpParserFactory;
use Rector\Core\PhpParser\Parser\PhpParserLexerFactory;
use Symfony\Component\Console\Application as SymfonyApplication;
@ -21,7 +20,6 @@ use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
@ -92,8 +90,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(StringFormatConverter::class);
$services->alias(EventDispatcherInterface::class, AutowiredEventDispatcher::class);
$services->set(SymfonyStyleFactory::class);
$services->set(SymfonyStyle::class)
->factory([ref(SymfonyStyleFactory::class), 'create']);

View File

@ -22,6 +22,7 @@ use Rector\CodingStyle\Rector\Function_\CamelCaseFunctionNamingToUnderscoreRecto
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
use Rector\CodingStyle\Rector\Include_\FollowRequireByDirRector;
use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector;
@ -69,4 +70,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(CamelCaseFunctionNamingToUnderscoreRector::class);
$services->set(SplitGroupedUseImportsRector::class);
$services->set(RemoveDoubleUnderscoreInMethodNameRector::class);
$services->set(PostIncDecToPreIncDecRector::class);
};

14
ecs.php
View File

@ -3,6 +3,7 @@
declare(strict_types=1);
use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff;
use PhpCsFixer\Fixer\Basic\Psr4Fixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
@ -79,6 +80,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
UnusedVariableSniff::class,
GlobalNamespaceImportFixer::class,
MethodDeclarationSniff::class . '.Underscore',
UnaryOperatorSpacesFixer::class,
// breaks on-purpose annotated variables
ReturnAssignmentFixer::class,
// buggy with specific markdown snippet file in docs/rules_overview.md
ArrayListItemNewlineFixer::class,
BlankLineAfterOpeningTagFixer::class,
Psr4Fixer::class,
PhpdocTypesFixer::class => [__DIR__ . '/rules/php74/src/Rector/Double/RealToFloatTypeCastRector.php'],
CommentedOutCodeSniff::class . '.Found' => [
@ -91,12 +99,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__ . '/tests/PhpParser/Node/NodeFactoryTest.php',
'*TypeResolverTest.php',
],
UnaryOperatorSpacesFixer::class,
// breaks on-purpose annotated variables
ReturnAssignmentFixer::class,
// buggy with specific markdown snippet file in docs/rules_overview.md
ArrayListItemNewlineFixer::class,
BlankLineAfterOpeningTagFixer::class,
StrictComparisonFixer::class => [__DIR__ . '/rules/polyfill/src/ConditionEvaluator.php'],

View File

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$services->load('Rector\Reporting\\', __DIR__ . '/../src')
->exclude([__DIR__ . '/../src/ValueObject']);
};

View File

@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Reporting\DataCollector;
use PhpParser\Node;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Reporting\ValueObject\Report;
final class ReportCollector
{
/**
* @var Report[]
*/
private $reports = [];
public function addFileAndLineAwareReport(string $report, Node $node, string $rectorClass): void
{
$smartFileInfo = $node->getAttribute(AttributeKey::FILE_INFO);
if ($smartFileInfo === null) {
throw new ShouldNotHappenException();
}
$this->reports[] = new Report($report, $rectorClass, $smartFileInfo, $node->getLine());
}
/**
* @return Report[]
*/
public function getReports(): array
{
return $this->reports;
}
}

View File

@ -1,80 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Reporting\EventSubscriber;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Configuration;
use Rector\Core\EventDispatcher\Event\AfterReportEvent;
use Rector\Reporting\DataCollector\ReportCollector;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @deprecated Replace with interface. Remove whole event system to keep 1 less pattern for same thing
*/
final class PrintReportCollectorEventSubscriber implements EventSubscriberInterface
{
/**
* @var ReportCollector
*/
private $reportCollector;
/**
* @var Configuration
*/
private $configuration;
/**
* @var SymfonyStyle
*/
private $symfonyStyle;
public function __construct(
Configuration $configuration,
ReportCollector $reportCollector,
SymfonyStyle $symfonyStyle
) {
$this->reportCollector = $reportCollector;
$this->configuration = $configuration;
$this->symfonyStyle = $symfonyStyle;
}
public function printReportCollector(): void
{
if ($this->shouldSkip()) {
return;
}
$this->symfonyStyle->title('Collected reports');
foreach ($this->reportCollector->getReports() as $report) {
$this->symfonyStyle->writeln($report->getRelativeFilePath() . ':' . $report->getLine());
$this->symfonyStyle->writeln('* ' . $report->getReport());
$this->symfonyStyle->writeln('* ' . $report->getRectorClass());
$this->symfonyStyle->newLine(2);
}
}
/**
* @return array<string, string>
*/
public static function getSubscribedEvents(): array
{
return [
AfterReportEvent::class => 'printReportCollector',
];
}
private function shouldSkip(): bool
{
// print only to console, not json etc.
if ($this->configuration->getOutputFormat() !== ConsoleOutputFormatter::NAME) {
return true;
}
return $this->reportCollector->getReports() === [];
}
}

View File

@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Reporting\Rector\AbstractRector;
use PhpParser\Node;
use Rector\Reporting\DataCollector\ReportCollector;
/**
* This could be part of @see AbstractRector, but decopuling to trait
* makes clear what code has 1 purpose.
*/
trait NodeReportCollectorTrait
{
/**
* @var ReportCollector
*/
protected $reportCollector;
/**
* @required
*/
public function autowireNodeReportCollectorTrait(ReportCollector $reportCollector): void
{
$this->reportCollector = $reportCollector;
}
protected function addReport(string $report, Node $node, string $rectorClass): void
{
$this->reportCollector->addFileAndLineAwareReport($report, $node, $rectorClass);
}
}

View File

@ -1,58 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Reporting\ValueObject;
use Symplify\SmartFileSystem\SmartFileInfo;
final class Report
{
/**
* @var int
*/
private $line;
/**
* @var string
*/
private $report;
/**
* @var string
*/
private $rectorClass;
/**
* @var SmartFileInfo
*/
private $smartFileInfo;
public function __construct(string $report, string $rectorClass, SmartFileInfo $smartFileInfo, int $line)
{
$this->smartFileInfo = $smartFileInfo;
$this->line = $line;
$this->report = $report;
$this->rectorClass = $rectorClass;
}
public function getRelativeFilePath(): string
{
return $this->smartFileInfo->getRelativeFilePathFromCwd();
}
public function getLine(): int
{
return $this->line;
}
public function getReport(): string
{
return $this->report;
}
public function getRectorClass(): string
{
return $this->rectorClass;
}
}

View File

@ -574,7 +574,6 @@ parameters:
- packages/better-php-doc-parser/src/PhpDocNode/PrintTagValueNodeTrait.php # 13
- packages/changes-reporting/src/Rector/AbstractRector/NotifyingRemovingNodeTrait.php # 17
- packages/post-rector/src/Rector/AbstractRector/NodeCommandersTrait.php # 31
- packages/reporting/src/Rector/AbstractRector/NodeReportCollectorTrait.php # 14
- rules/doctrine/src/AbstractRector/DoctrineTrait.php # 13
- src/Rector/AbstractRector/*
@ -718,6 +717,5 @@ parameters:
- '#Method (.*?) should return DOMElement but returns DOMElement\|false#'
- '#Method (.*?) should return DOMElement\|null but returns DOMElement\|false#'
# bug in simplify
- '#Parameter 1 should use PhpParser\\Node\\Expr\\MethodCall type as already checked#'

View File

@ -2,19 +2,18 @@
declare(strict_types=1);
namespace Rector\Doctrine\EventSubscriber;
namespace Rector\Doctrine\PostRunner;
use Nette\Utils\Json;
use Rector\Core\EventDispatcher\Event\AfterProcessEvent;
use Rector\Core\Contract\PostRunnerInterface;
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symplify\SmartFileSystem\SmartFileSystem;
/**
* @deprecated Replace with interface. Remove whole event system to keep 1 less pattern for same thing
*/
final class ReportEntitiesWithAddedPropertiesEventSubscriber implements EventSubscriberInterface
final class ReportEntitiesWithAddedPropertiesPostRunner implements PostRunnerInterface
{
/**
* @var UuidMigrationDataCollector
@ -41,7 +40,7 @@ final class ReportEntitiesWithAddedPropertiesEventSubscriber implements EventSub
$this->smartFileSystem = $smartFileSystem;
}
public function reportEntities(): void
public function run(): void
{
$this->generatePropertiesJsonWithFileName(
'uuid-migration-new-column-properties.json',
@ -54,16 +53,6 @@ final class ReportEntitiesWithAddedPropertiesEventSubscriber implements EventSub
);
}
/**
* @return array<string, string>
*/
public static function getSubscribedEvents(): array
{
return [
AfterProcessEvent::class => 'reportEntities',
];
}
/**
* @param mixed[] $data
*/

View File

@ -8,11 +8,11 @@ class FixtureClass
{
compact('posts','units',);
$this->setData('posts','units',);
self::run('posts','units',);
self::run('posts',
'units',);
$this->setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId,)}",);
}
}
@ -28,10 +28,10 @@ class FixtureClass
{
compact('posts', 'units');
$this->setData('posts', 'units');
self::run('posts', 'units');
self::run('posts', 'units');
$this->setOnClick("[Zip ID: {$modelid}] {{$e->getMessage($modelId)}}");
self::run('posts', 'units');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector\Fixture;
class InStringVariable
{
public function run()
{
$this->setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId,)}",);
}
}
?>
-----
<?php
namespace Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector\Fixture;
class InStringVariable
{
public function run()
{
$this->setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId)}");
}
}
?>

View File

@ -10,11 +10,10 @@ use Rector\ChangesReporting\Application\ErrorAndDiffCollector;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Configuration\Configuration;
use Rector\Core\EventDispatcher\Event\AfterProcessEvent;
use Rector\Core\Contract\PostRunnerInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
use Symplify\SmartFileSystem\SmartFileInfo;
use Throwable;
@ -47,6 +46,11 @@ final class RectorApplication
*/
private $notParsedFiles = [];
/**
* @var PostRunnerInterface[]
*/
private $postRunners = [];
/**
* @var SymfonyStyle
*/
@ -82,26 +86,24 @@ final class RectorApplication
*/
private $nodeScopeResolver;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var PrivatesAccessor
*/
private $privatesAccessor;
/**
* @param PostRunnerInterface[] $postRunners
*/
public function __construct(
Configuration $configuration,
ErrorAndDiffCollector $errorAndDiffCollector,
EventDispatcherInterface $eventDispatcher,
FileProcessor $fileProcessor,
NodeScopeResolver $nodeScopeResolver,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
SymfonyStyle $symfonyStyle,
PrivatesAccessor $privatesAccessor
PrivatesAccessor $privatesAccessor,
array $postRunners
) {
$this->symfonyStyle = $symfonyStyle;
$this->errorAndDiffCollector = $errorAndDiffCollector;
@ -110,8 +112,8 @@ final class RectorApplication
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
$this->removedAndAddedFilesProcessor = $removedAndAddedFilesProcessor;
$this->nodeScopeResolver = $nodeScopeResolver;
$this->eventDispatcher = $eventDispatcher;
$this->privatesAccessor = $privatesAccessor;
$this->postRunners = $postRunners;
}
/**
@ -157,7 +159,9 @@ final class RectorApplication
$this->removedAndAddedFilesProcessor->run();
// 5. various extensions on finish
$this->eventDispatcher->dispatch(new AfterProcessEvent());
foreach ($this->postRunners as $postRunner) {
$postRunner->run();
}
}
private function prepareProgressBar(int $fileCount): void

View File

@ -14,7 +14,6 @@ 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\NonPhpFile\NonPhpFileProcessor;
@ -26,7 +25,6 @@ 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\ShellCode;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -87,11 +85,6 @@ final class ProcessCommand extends AbstractCommand
*/
private $symfonyStyle;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var CachedFileInfoFilterAndReporter
*/
@ -102,7 +95,6 @@ final class ProcessCommand extends AbstractCommand
ChangedFilesDetector $changedFilesDetector,
Configuration $configuration,
ErrorAndDiffCollector $errorAndDiffCollector,
EventDispatcherInterface $eventDispatcher,
FilesFinder $phpFilesFinder,
NonPhpFileProcessor $nonPhpFileProcessor,
OutputFormatterCollector $outputFormatterCollector,
@ -125,7 +117,6 @@ final class ProcessCommand extends AbstractCommand
$this->nonPhpFileProcessor = $nonPhpFileProcessor;
$this->changedFilesDetector = $changedFilesDetector;
$this->symfonyStyle = $symfonyStyle;
$this->eventDispatcher = $eventDispatcher;
$this->cachedFileInfoFilterAndReporter = $cachedFileInfoFilterAndReporter;
parent::__construct();
@ -231,8 +222,6 @@ final class ProcessCommand extends AbstractCommand
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
$outputFormatter->report($this->errorAndDiffCollector);
$this->eventDispatcher->dispatch(new AfterReportEvent());
// invalidate affected files
$this->invalidateAffectedCacheFiles();

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Contract;
interface PostRunnerInterface
{
public function run(): void;
}

View File

@ -1,27 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\EventDispatcher;
use Rector\Core\ValueObject\MethodName;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class AutowiredEventDispatcher extends EventDispatcher
{
/**
* @param EventSubscriberInterface[] $eventSubscribers
*/
public function __construct(array $eventSubscribers)
{
foreach ($eventSubscribers as $eventSubscriber) {
$this->addSubscriber($eventSubscriber);
}
// Symfony 4.4/5 compat
if (method_exists(parent::class, MethodName::CONSTRUCT)) {
parent::__construct();
}
}
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
/**
* @deprecated Replace with interface. Remove whole event system to keep 1 less pattern for same thing
*/
final class AfterProcessEvent extends Event
{
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
/**
* @deprecated Replace with interface. Remove whole event system to keep 1 less pattern for same thing
*/
final class AfterReportEvent extends Event
{
}

View File

@ -11,7 +11,6 @@ use Rector\ChangesReporting\Rector\AbstractRector\NotifyingRemovingNodeTrait;
use Rector\Doctrine\AbstractRector\DoctrineTrait;
use Rector\FileSystemRector\Behavior\FileSystemRectorTrait;
use Rector\PostRector\Rector\AbstractRector\NodeCommandersTrait;
use Rector\Reporting\Rector\AbstractRector\NodeReportCollectorTrait;
trait AbstractRectorTrait
{
@ -31,7 +30,6 @@ trait AbstractRectorTrait
use ComplexRemovalTrait;
use NodeCollectorTrait;
use NotifyingRemovingNodeTrait;
use NodeReportCollectorTrait;
protected function isNonAnonymousClass(?Node $node): bool
{