-
-
Notifications
You must be signed in to change notification settings - Fork 431
[type-declarations] Open isset check in StrictArrayParamDimFetchRectorTest, move to last position in type-declaration level #7388
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
26d22aa to
f119912
Compare
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.
There is rule StrictArrayParamDimFetchRector rule for it, for 0 index without context, it can be string, which maybe not array on purpose, see
rector-src/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php
Lines 173 to 177 in edadebb
| // skip integer in possibly string type as string can be accessed via int | |
| $dimType = $this->getType($node->dim); | |
| if ($dimType->isInteger()->yes() && $variableType->isString()->maybe()) { | |
| return null; | |
| } |
|
I could not find this one, thanks I see lot of missed array types just to avoid string access. Will make this condition less strict to improve auto fill 👍 |
|
Then that's need on very last on level set list with Also, still needs |
5c1b4b8 to
a5d9773
Compare
a5d9773 to
b2dd4a7
Compare
…rTest, move to last position in type-declaration level
2bc2bc4 to
88a4185
Compare
|
|
||
| final class CoverIssetWithDimFetch | ||
| { | ||
| public function run(array $param, $item): bool |
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.
in this case $param could be anything which implements ArrayAccess not just the rare case of string-offset access.
in case you "wrongly guess" the array type a call with a ArrayAccess object will produce a fatal error at runtime - see https://3v4l.org/csROV
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.
Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.
If your codebase uses any type in this case, exclude the 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.
Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.
If your codebase uses any type in this case, exclude the rule.
In one project I've noticed there is no
arrayfilled where obviously should be one.Single
issetmight be triggered on null and key, but maybe more useful cases are ignored then. Let's open up this a bit and test in the wild, if brings more value 👍