-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
RemoveUnusedNonEmptyArrayBeforeForeachRector: ignore phpdoc types #5169
Conversation
{ | ||
$this->items = $items; | ||
} | ||
private array $items = []; | ||
|
||
public function run() | ||
{ |
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.
IMO this test was wrong because we can't know the type of $this->items
(it is mixed
in this case)
-> I simplified the test-case and made sure it works on a native array
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.
no, it is clearly set :
- default array on property level
- assigned with always array
the type will always be array.
Changing to typed property will reduce the functionality of upgrading to better code.
We don't need to ensure the outside object fill usage as that out of scope.
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 can't know whether the class has some other method which overrides the property with any non-array type - at least the rector rule does not do the necessary checks to verify it , or does it?
see e.g. https://getrector.com/demo/a7d43fbd-c848-47e4-9ba2-bd9e6438746c
assignment of a default value via construct does not verify the type will never change (at least not for a non-typed property)
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.
That seems code smell, and the app already crash from the beginning if not filled with proper data for that truthy check then foreach it, like other PR, on runtime perspective.
The issue with more and more skipping things like that will reduce the usability of upgrading to better code itself.
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.
Ok, combine with TypedPropertyFromAssignsRector
seems can be solution to keep up the empty removal, as after it typed, the empty will be removable if always array filled.
Just the non-array type empty check then foreach is a bit strange use case, which I can't found in real life yet which fatal error is "the correct one" since checked on runtime.
@TomasVotruba I am going to merge this because of the rule named RemoveUnusedNonEmptyArrayBeforeForeachRector
for arrays.
Thank you @staabm |
No description provided.