Enhance type inference for the Dispatch Method by adding a @template Annotation#33
Open
rkrx wants to merge 1 commit intophp-fig:masterfrom
Open
Enhance type inference for the Dispatch Method by adding a @template Annotation#33rkrx wants to merge 1 commit intophp-fig:masterfrom
rkrx wants to merge 1 commit intophp-fig:masterfrom
Conversation
…Annotation `@template` was added to indicate that the same type is returned that was passed as an object to the dispatch method. This change is useful because static code analysers would otherwise interpret the return of the dispatch method as a generic object. See [before](https://phpstan.org/r/16b67279-1560-451c-b00d-a9c224864ee2) and [after](https://phpstan.org/r/06555e83-cdcc-45ff-a25f-3024b4b2b1b6).
Contributor
|
We don't yet as FIG have a policy on whether or not to use "extended" docblock syntax like PHPStan and Psalm use. I absolutely agree typing this would be useful, but we should make sure FIG as a whole is on board. Can you start a brief conversation on list, to get the overall temperature on this question? |
Contributor
|
(And then there's the divergence from the PSR text itself question to answer, too.) |
Member
|
I'm onboard with this |
|
I was just looking in code and I think also the /**
* @template T of object
*
* @param T $event
* An event for which to return the relevant listeners.
* @return iterable[callable(T): void]
* An iterable (array, iterator, or generator) of callables. Each
* callable MUST be type-compatible with $event.
*/
public function getListenersForEvent(object $event) : iterable;and I think it can go together . I think we should start that discussion on the list (https://groups.google.com/g/php-fig/). I'll try to look into this. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
@templatewas added to indicate that the same type is returned that was passed as an object to the dispatch method. This change is useful because static code analysers would otherwise interpret the return of the dispatch method as a generic object. See before and after.