From e5d26b095511cb0376f698f3af592470c33a74e3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 10 Dec 2024 10:32:16 +0000 Subject: [PATCH] Updated Rector to commit 1e028eba0d8b7c131423f1d98cd2fde5f0838b03 https://github.com/rectorphp/rector-src/commit/1e028eba0d8b7c131423f1d98cd2fde5f0838b03 [upgrading] link phpstan + php-parser upgrade guides (#6542) --- README.md | 4 +- UPGRADING.md | 95 +++++++++++++++++++++++++++++ src/Application/VersionResolver.php | 4 +- 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 UPGRADING.md diff --git a/README.md b/README.md index 36dc7effb34..fe5c9744613 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Rector instantly upgrades and refactors the PHP code of your application. It ca ### 1. Instant Upgrades -Rector now supports upgrades from PHP 5.3 to 8.2 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**? +Rector now supports upgrades from PHP 5.3 to 8.4 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**? Use Rector to handle **instant upgrades** for you. @@ -162,4 +162,4 @@ We're using [ECS](https://github.com/symplify/easy-coding-standard) with [this s ### May cause unexpected output on File with mixed PHP+HTML content -When you apply changes to File(s) thas has mixed PHP+HTML content, you may need to manually verify the changed file after apply the changes. +When you apply changes to files with PHP + HTML content, you may need to manually verify the changed file after apply the changes. diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 00000000000..a3fe6593f4b --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,95 @@ +# Upgrading from Rector 1.x to 2.0 + +## PHP version requirements + +Rector now uses PHP 7.4 or newer to run. + +
+ +## Rector now uses PHP-Parser 5 + +See [upgrading guide](https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md) for PHP-Parser. + +
+ +## Rector now uses PHPStan 2 + +See [upgrading guide](https://github.com/phpstan/phpstan-src/blob/2.0.x/UPGRADING.md) for PHPStan. + +
+ +## Upgrade for custom Rules writers + +### 1. `AbstractScopeAwareRector` is removed, use `AbstractRector` instead + +The `Rector\Rector\AbstractScopeAwareRector` was too granular to fetch single helper object. It made creating new custom rules ambiguous, one layer more complex and confusing. This class has been removed in favor of standard `AbstractRector`. The `Scope` object can be fetched via `ScopeFetcher`. + +**Before** + +```php +use Rector\Rector\AbstractScopeAwareRector; + +final class SimpleRector extends AbstractScopeAwareRector +{ + public function refactorWithScope(Node $node, Scope $scope): ?Node + { + // ... + } +} +``` + +**After** + +```php +use Rector\Rector\AbstractRector; +use Rector\PHPStan\ScopeFetcher; + +final class SimpleRector extends AbstractRector +{ + public function refactor(Node $node): ?Node + { + if (...) { + // this allow to fetch scope only when needed + $scope = ScopeFetcher::fetch($node); + } + + // ... + } +} +``` + + +### 2. `AbstractRector` get focused on code, the `getRuleDefinition()` is no longer required + +Core rules need documentation, so people can read their feature and [search through](https://getrector.com/find-rule) them. Yet for writing custom rules and local rules, its not necessary. People often filled it empty, just to make Rector happy. + +This is no longer needed. Now The `getRuleDefinition()` method has been removed: + +```diff + use Rector\Rector\AbstractRector; +-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; + + final class SimpleRector extends AbstractRector + { +- public function getRuleDefinition(): RuleDefinition +- { +- return new RuleDefinition('// @todo fill the description', [ +- new CodeSample( +- <<<'CODE_SAMPLE' +-// @todo fill code before +-CODE_SAMPLE +- , +- <<<'CODE_SAMPLE' +-// @todo fill code after +-CODE_SAMPLE +- ), +- ]); +- } + + // valuable code here + } +``` + +If you need description yourself to understand rule after many months, use the common place for documentation - docblock above class. + diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 50829687d26..ed073a3e240 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '481591a08a2780de32ec405046ab7b2920d72349'; + public const PACKAGE_VERSION = '1e028eba0d8b7c131423f1d98cd2fde5f0838b03'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-10 09:44:15'; + public const RELEASE_DATE = '2024-12-10 11:29:51'; /** * @var int */