-
Notifications
You must be signed in to change notification settings - Fork 538
Get rid of of Type::getArrays()
usage in InvalidKeyInArrayDimFetchRule
#1872
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
Get rid of of Type::getArrays()
usage in InvalidKeyInArrayDimFetchRule
#1872
Conversation
tests/PHPStan/Rules/Arrays/data/invalid-key-array-dim-fetch.php
Outdated
Show resolved
Hide resolved
d05db1f
to
b9eec50
Compare
This pull request has been marked as ready for review. |
e329ade
to
2a4e824
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.
The rest of this method should be:
if ($isSuperType-yes()) {
return [];
}
return [
RuleErrorBuilder::message(
sprintf('%s array key type %s.', $isSuperType->no() ? 'Invalid' : 'Possibly invalid', $dimensionType->describe(VerbosityLevel::typeOnly())),
)->build(),
];
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 looks better! adapted. but I had to keep the maybe-early-exit in to avoid the rule reporting maybes on level 3 already (the newly added levelstest case started failing)
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.
oh and I forgot to run make phpstan before pushing. need to check what's going on with mixed there which should be ignored still I guess
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's a bit weird because RuleLevelHelper should have already taken care of the maybe case on lower levels.
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.
also had a feeling that the closure is maybe still wrong, but RuleLevelHelper doesn't seem to be dealing with checkMaybe? it deals with e.g. checkUnionTypes, but in my case the union is irrelevant, the int dim on a constantarray is a maybe :/
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.
Oh, you're right, the rule code needs to be a bit more complicated after all. Not sure what's with the mixed in make phpstan
, PHPStan is running on level 8...
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 rule was explicitly ignoring mixed dims before as well when checking for maybe/potential invalid keys. maybe it can't be simplified after all. I was also looking forward to put all checks on top and into the closure
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 mixed dims that were reported seemed mostly legit, maybe this could even be turned on with bleedingEdge. but it's not related to this PR I think, I let the rule ignore them again. at least it's a bit simpler and makes use of RuleLevelHelper now hmm
00c4eb2
to
dbf34a2
Compare
Thank you! |
this thing just keeps annoying me and I want to do something about it. of course I dislike the
instanceof MixedType
, but maybe someone has a better idea?