-
Notifications
You must be signed in to change notification settings - Fork 541
Respect phpstan level in InvalidKeyInArrayDimFetchRule #4166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d159794
Add integration test
VincentLanglet 23cfa4c
Fix InvalidKeyInArrayDimFetchRule
VincentLanglet 90ef5c4
Fix RuleLevelHelper
VincentLanglet bc59757
Fix lint
VincentLanglet 6f99f04
Add more cases
VincentLanglet 7e0f73b
Improve
VincentLanglet 03b04f5
Fix level 9
VincentLanglet 9628a15
Fix level 10
VincentLanglet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"message": "Possibly invalid array key type mixed.", | ||
"line": 22, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type mixed.", | ||
"line": 31, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset 42 on mixed.", | ||
"line": 42, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset null on mixed.", | ||
"line": 43, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset DateTimeImmutable on mixed.", | ||
"line": 44, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset int|null on mixed.", | ||
"line": 45, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset int|object on mixed.", | ||
"line": 46, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset object|null on mixed.", | ||
"line": 47, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset mixed on mixed.", | ||
"line": 48, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset mixed on mixed.", | ||
"line": 49, | ||
"ignorable": true | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"message": "Invalid array key type DateTimeImmutable.", | ||
"line": 17, | ||
"ignorable": true | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
[ | ||
{ | ||
"message": "Expression \"$a[42]\" on a separate line does not do anything.", | ||
"line": 15, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[null]\" on a separate line does not do anything.", | ||
"line": 16, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[$intOrNull]\" on a separate line does not do anything.", | ||
"line": 18, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[$objectOrInt]\" on a separate line does not do anything.", | ||
"line": 19, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[$objectOrNull]\" on a separate line does not do anything.", | ||
"line": 20, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[$explicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 21, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$a[$implicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 22, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[42]\" on a separate line does not do anything.", | ||
"line": 24, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[null]\" on a separate line does not do anything.", | ||
"line": 25, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[$intOrNull]\" on a separate line does not do anything.", | ||
"line": 27, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[$objectOrInt]\" on a separate line does not do anything.", | ||
"line": 28, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[$objectOrNull]\" on a separate line does not do anything.", | ||
"line": 29, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[$explicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 30, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$arrayOrObject[$implicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 31, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[42]\" on a separate line does not do anything.", | ||
"line": 33, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[null]\" on a separate line does not do anything.", | ||
"line": 34, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[$intOrNull]\" on a separate line does not do anything.", | ||
"line": 36, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[$objectOrInt]\" on a separate line does not do anything.", | ||
"line": 37, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[$objectOrNull]\" on a separate line does not do anything.", | ||
"line": 38, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[$explicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 39, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$explicitlyMixed[$implicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 40, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[42]\" on a separate line does not do anything.", | ||
"line": 42, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[null]\" on a separate line does not do anything.", | ||
"line": 43, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[$intOrNull]\" on a separate line does not do anything.", | ||
"line": 45, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[$objectOrInt]\" on a separate line does not do anything.", | ||
"line": 46, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[$objectOrNull]\" on a separate line does not do anything.", | ||
"line": 47, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[$explicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 48, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Expression \"$implicitlyMixed[$implicitlyMixed]\" on a separate line does not do anything.", | ||
"line": 49, | ||
"ignorable": true | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $a with no value type specified in iterable type array.", | ||
"line": 13, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $arrayOrObject with generic interface ArrayAccess but does not specify its types: TKey, TValue", | ||
"line": 13, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $arrayOrObject with no value type specified in iterable type array.", | ||
"line": 13, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $implicitlyMixed with no type specified.", | ||
"line": 13, | ||
"ignorable": true | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[ | ||
{ | ||
"message": "Possibly invalid array key type int|object.", | ||
"line": 19, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type object|null.", | ||
"line": 20, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type DateTimeImmutable.", | ||
"line": 26, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type int|object.", | ||
"line": 28, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type object|null.", | ||
"line": 29, | ||
"ignorable": true | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"message": "Possibly invalid array key type mixed.", | ||
"line": 21, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Possibly invalid array key type mixed.", | ||
"line": 30, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset 42 on mixed.", | ||
"line": 33, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset null on mixed.", | ||
"line": 34, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset DateTimeImmutable on mixed.", | ||
"line": 35, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset int|null on mixed.", | ||
"line": 36, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset int|object on mixed.", | ||
"line": 37, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset object|null on mixed.", | ||
"line": 38, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset mixed on mixed.", | ||
"line": 39, | ||
"ignorable": true | ||
}, | ||
{ | ||
"message": "Cannot access offset mixed on mixed.", | ||
"line": 40, | ||
"ignorable": true | ||
} | ||
] |
Oops, something went wrong.
Oops, something went wrong.
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.
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'm still wondering about what's the effect of the
$varType
going through RuleLevelHelper. Does something change if we get rid of it only continue if$scope->getType($node->var)->isArray()->yes()
?It's weird to me that this rule checks maybe-arrays. It's okay for
array|null
for example, but I'm not sure if it ever should report something onmixed
.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 more test case here with the commit 6f99f04
You can see that
StrictMixedType
in whichisArray()
return no.But it was right to report I need to check the result for maybe array.
The error message was
Invalid array key type DateTimeImmutable.
, I think it should bePossibly invalid array key type DateTimeImmutable.
then. And I fix that in the commit 7e0f73b