-
-
Notifications
You must be signed in to change notification settings - Fork 424
[stmts-aware] Deprecate the interface and replace with meta-type + groups #7679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
56fa5ad to
b556e80
Compare
| * Inspired by https://github.com/phpstan/phpstan-src/commit/ed81c3ad0b9877e6122c79b4afda9d10f3994092 | ||
| */ | ||
| final class FileWithoutNamespace extends Stmt implements StmtsAwareInterface | ||
| final class FileWithoutNamespace extends Stmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Will add it 👍
…neAfterStatementRector
977ad35 to
e6a5b1a
Compare
75b3af7 to
ff56253
Compare
|
Let's go 👍 |
|
see my review comment #7679 (review) |
|
Done 09bd026 |
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: