Skip to content

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Oct 19, 2022

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?

@herndlm herndlm marked this pull request as draft October 19, 2022 09:45
@herndlm herndlm force-pushed the get-arrays-invalid-key-in-array-dim-fetch-rule branch from d05db1f to b9eec50 Compare October 19, 2022 10:44
@herndlm herndlm marked this pull request as ready for review October 19, 2022 11:03
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm herndlm force-pushed the get-arrays-invalid-key-in-array-dim-fetch-rule branch 2 times, most recently from e329ade to 2a4e824 Compare October 19, 2022 18:08
Copy link
Member

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(),
];

Copy link
Contributor Author

@herndlm herndlm Oct 21, 2022

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)

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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 :/

Copy link
Member

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...

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@herndlm herndlm force-pushed the get-arrays-invalid-key-in-array-dim-fetch-rule branch from 00c4eb2 to dbf34a2 Compare October 21, 2022 18:32
@herndlm herndlm requested a review from ondrejmirtes October 21, 2022 18:46
@ondrejmirtes ondrejmirtes merged commit d857d58 into phpstan:1.9.x Oct 24, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the get-arrays-invalid-key-in-array-dim-fetch-rule branch October 24, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants