feat: add dynamic parameter type extensions #4290
Open
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.
Closes phpstan/phpstan#11707, closes phpstan/phpstan#12585
Supersedes #3828, supersedes #3131, supersedes #3823
Hello!
This adds generalized dynamic parameter type extensions and deprecates the parameter closure type extensions per phpstan/phpstan#11707 (comment).
This also fixes the
return.type
and theargument.type
errors described in phpstan/phpstan#12585 when the parameter type is overridden via the extension.Note
The original type from the closure type extensions was being passed around as
$passedToType
to the methods that needed it. However, with the new extensions the type must be passed around more, instead of adding parameter types to all the methods, I opted to add it to the ExpressionContext object that was already being passed around (given that this is context and whatnot) asoverriddenType
since I wasn't quite sure what$passedToType
really meant. Let me know if there's something you'd rather do differently.CC: @canvural, @Neol3108
Thanks!