diff --git a/composer.json b/composer.json index d29fa0a1f4f..b94daf9610d 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/services.php b/config/services.php index ca4eaa3b5fa..99e038a3a9c 100644 --- a/config/services.php +++ b/config/services.php @@ -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']); diff --git a/config/set/coding-style.php b/config/set/coding-style.php index 11e4ed25f25..bb49208a2fa 100644 --- a/config/set/coding-style.php +++ b/config/set/coding-style.php @@ -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); }; diff --git a/ecs.php b/ecs.php index 74b75e8581b..7ceeb50ccc0 100644 --- a/ecs.php +++ b/ecs.php @@ -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'], diff --git a/packages/reporting/config/config.php b/packages/reporting/config/config.php deleted file mode 100644 index 7c88f68290c..00000000000 --- a/packages/reporting/config/config.php +++ /dev/null @@ -1,17 +0,0 @@ -services(); - - $services->defaults() - ->public() - ->autowire() - ->autoconfigure(); - - $services->load('Rector\Reporting\\', __DIR__ . '/../src') - ->exclude([__DIR__ . '/../src/ValueObject']); -}; diff --git a/packages/reporting/src/DataCollector/ReportCollector.php b/packages/reporting/src/DataCollector/ReportCollector.php deleted file mode 100644 index 259e7c36e86..00000000000 --- a/packages/reporting/src/DataCollector/ReportCollector.php +++ /dev/null @@ -1,36 +0,0 @@ -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; - } -} diff --git a/packages/reporting/src/EventSubscriber/PrintReportCollectorEventSubscriber.php b/packages/reporting/src/EventSubscriber/PrintReportCollectorEventSubscriber.php deleted file mode 100644 index 7311bd9f7e0..00000000000 --- a/packages/reporting/src/EventSubscriber/PrintReportCollectorEventSubscriber.php +++ /dev/null @@ -1,80 +0,0 @@ -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 - */ - 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() === []; - } -} diff --git a/packages/reporting/src/Rector/AbstractRector/NodeReportCollectorTrait.php b/packages/reporting/src/Rector/AbstractRector/NodeReportCollectorTrait.php deleted file mode 100644 index fb4b0c11c18..00000000000 --- a/packages/reporting/src/Rector/AbstractRector/NodeReportCollectorTrait.php +++ /dev/null @@ -1,33 +0,0 @@ -reportCollector = $reportCollector; - } - - protected function addReport(string $report, Node $node, string $rectorClass): void - { - $this->reportCollector->addFileAndLineAwareReport($report, $node, $rectorClass); - } -} diff --git a/packages/reporting/src/ValueObject/Report.php b/packages/reporting/src/ValueObject/Report.php deleted file mode 100644 index 56f68788421..00000000000 --- a/packages/reporting/src/ValueObject/Report.php +++ /dev/null @@ -1,58 +0,0 @@ -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; - } -} diff --git a/phpstan.neon b/phpstan.neon index ac67fb719be..59eb4190cf0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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#' diff --git a/rules/doctrine/src/EventSubscriber/ReportEntitiesWithAddedPropertiesEventSubscriber.php b/rules/doctrine/src/PostRunner/ReportEntitiesWithAddedPropertiesPostRunner.php similarity index 78% rename from rules/doctrine/src/EventSubscriber/ReportEntitiesWithAddedPropertiesEventSubscriber.php rename to rules/doctrine/src/PostRunner/ReportEntitiesWithAddedPropertiesPostRunner.php index 90cfd76253f..4254b9b4568 100644 --- a/rules/doctrine/src/EventSubscriber/ReportEntitiesWithAddedPropertiesEventSubscriber.php +++ b/rules/doctrine/src/PostRunner/ReportEntitiesWithAddedPropertiesPostRunner.php @@ -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 - */ - public static function getSubscribedEvents(): array - { - return [ - AfterProcessEvent::class => 'reportEntities', - ]; - } - /** * @param mixed[] $data */ diff --git a/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc index b88fb7fcc8d..28f00934873 100644 --- a/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc +++ b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc @@ -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'); } } diff --git a/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/in_stirng_variable.php.inc b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/in_stirng_variable.php.inc new file mode 100644 index 00000000000..802fd27d8e5 --- /dev/null +++ b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/in_stirng_variable.php.inc @@ -0,0 +1,27 @@ +setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId,)}",); + } +} + +?> +----- +setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId)}"); + } +} + +?> diff --git a/src/Application/RectorApplication.php b/src/Application/RectorApplication.php index 41d87ba691d..a81332aad6a 100644 --- a/src/Application/RectorApplication.php +++ b/src/Application/RectorApplication.php @@ -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 diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 61bc109f874..ef46b203c06 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -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(); diff --git a/src/Contract/PostRunnerInterface.php b/src/Contract/PostRunnerInterface.php new file mode 100644 index 00000000000..d1ac5f2590e --- /dev/null +++ b/src/Contract/PostRunnerInterface.php @@ -0,0 +1,10 @@ +addSubscriber($eventSubscriber); - } - - // Symfony 4.4/5 compat - if (method_exists(parent::class, MethodName::CONSTRUCT)) { - parent::__construct(); - } - } -} diff --git a/src/EventDispatcher/Event/AfterProcessEvent.php b/src/EventDispatcher/Event/AfterProcessEvent.php deleted file mode 100644 index 868c35a1100..00000000000 --- a/src/EventDispatcher/Event/AfterProcessEvent.php +++ /dev/null @@ -1,14 +0,0 @@ -