[stmts-aware] Deprecate the interface and replace with meta-type + groups#7679
Merged
TomasVotruba merged 9 commits intomainfrom Nov 28, 2025
Merged
[stmts-aware] Deprecate the interface and replace with meta-type + groups#7679TomasVotruba merged 9 commits intomainfrom
TomasVotruba merged 9 commits intomainfrom
Conversation
56fa5ad to
b556e80
Compare
samsonasik
reviewed
Nov 28, 2025
samsonasik
reviewed
Nov 28, 2025
This was referenced Nov 28, 2025
Merged
Merged
samsonasik
reviewed
Nov 28, 2025
| * Inspired by https://github.com/phpstan/phpstan-src/commit/ed81c3ad0b9877e6122c79b4afda9d10f3994092 | ||
| */ | ||
| final class FileWithoutNamespace extends Stmt implements StmtsAwareInterface | ||
| final class FileWithoutNamespace extends Stmt |
Member
There was a problem hiding this comment.
For this PR, this should keep implements StmtsAwareInterface as it not yet update composer.json patch.
There should be no down in the process as possible before it actually fully migrated.
Member
Author
There was a problem hiding this comment.
Good point. Will add it 👍
…neAfterStatementRector
977ad35 to
e6a5b1a
Compare
75b3af7 to
ff56253
Compare
Member
Author
|
Let's go 👍 |
Member
|
see my review comment #7679 (review) |
Member
Author
|
Done 09bd026 |
This was referenced Nov 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step to solve rectorphp/rector#9416
This PR:
Rector\Contract\PhpParser\Node\StmtsAwareInterfaceused in/vendorpatchesPhpParser\Node+ PHPStan meta type/vendorpatching and preload (to be tested first, patches will remain for now to inform about deprecation) - this has been huge pain past 4 years, time to solve it 💪Next steps before merge:
rector/rector-*packagesHow to upgrade custom rules?
If you're using
StmtsAwareInterface, there are 2 changes needed. First, update your Rector rule:public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return \Rector\PhpParser\Enum\NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): ?Node { + // check property stmts exists, e.g. propery_exists($node, 'stmts') + // or using Assert::propertyExists(...) }In case you're using the interface in
instanceofcheck, upgrade this way:Second, get help from PHPStan with the union type analysis. The
StmtsAwareis a special global alias PHPStan type, that have to be added tophpstan.neon.This will allow to static analysis to work as previously: