Add mixed type hint for magic properties #443
Closed
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.
Description of the problem
While using Dibi with PhpStorm (the prevalent PHP IDE), I'm constantly being warned about using void where I should not.
I'm pushed to either disable the inspection or suppress it for the given statement/block etc.
But this inspection is useful and I do not wish to suppress it.
Solution of the problem
Instead, we can just add
mixed
return type-hint to the magicRow::__get
method to "confuse" PhpStorm.We can do this, because we are actually using
Row
magically without type safety so there is no sacrifice to make. Withmixed
as the return value type, PS accepts it can not infer the type of the property and stops complaining.We can then omit the suppressions
and we end up with clean code:
We are still warned that we acces the properties using "magic" (Property accessed via magic method).