-
-
Notifications
You must be signed in to change notification settings - Fork 429
[TypeDeclaration] Handle Anonymous class extends existing class in union #3161
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
[TypeDeclaration] Handle Anonymous class extends existing class in union #3161
Conversation
|
Fixed 🎉 |
| } | ||
|
|
||
| return null; | ||
| } |
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.
What is this for?
This rule should only change the strict type declarations and avoid docblocks.
Also this can report false positive change in case of docblock changed by another previous rule.
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.
it called when only change docblock, see in line 131, no type changed, only change docblock, then check PhpDocInfo is changed.
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.
We currently stil mark DateTime|null as union type in UnionTypeMapper, not Nullable, so then we use docblock in PHP 7.4 feature set.
That need separate PR to make it nullable compatible DateTime|null marked as nullable type in PHP 7.4, ref https://3v4l.org/4HTQT#v7.4.33
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.
I added new fixture for php 8.x feature set to make it strict typed https://github.com/rectorphp/rector-src/pull/3161/files#diff-1dfc0caeebe902ff508cdf3b3bc6d0a09ea00526c8c7ff572f75bbd0c51f4a77
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.
I added another fixture for php 8.x feature enabled to remove existing docblock d12ba31
- The default test is using php 7.4 feature, so it uses docblock ( union nullable still marked as union, not nullable)
- when we use php 8.x feature on
FixtureComplexTypesdirectory, it uses fully php 8.x feature.
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.
The goal is to avoid changing docblocks in anyway, as they can be used later as relly on strict-type declarations.
Instead the code on PHP 7.4- for union types should be skipped, and strict union type added only in PHP 8.0.
That way we always add types that are known and strict 👍
|
I'll merge this as a fix for extra |
In PHP 7.4 feature set, given the following code with
new class extendsusage:it currently produce diff:
ref https://getrector.org/demo/7be14431-6643-4dd6-8edb-98f533cf9002
which the
objectis extendsDateTime, which can be removed and use:instead. This PR try to handle it.