-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[EventDispatcher] Declare return type of getSubscribedEvents()
#41995
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
Conversation
Fixes Method getSubscribedEvents() return type has no value type specified in iterable type array. 💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
getSubscribedEvents()
@@ -43,7 +43,7 @@ interface EventSubscriberInterface | |||
* The code must not depend on runtime state as it will only be called at compile time. | |||
* All logic depending on runtime state must be put into the individual methods handling the events. | |||
* | |||
* @return array The event names to listen to | |||
* @return array<string, mixed> The event names to listen to |
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.
Can we use something more explicit than mixed? Personally I try to use union's as much as possible.
Like array<string, string|array{0: string}|array{0: string, 1: int}|array<int, array{0: string}|array{0: string, 1: int}>>
And yes it's a bit verbose 😄
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's actually not the right signature. the right one is this:
array<string, string|array{0: string, 1?: int}|list<array{0: string, 1?: int}>>
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.
OK, you edited in the meantime. Your new proposal is too verbose due to not using the optional key for the priority
There was a problem hiding this comment.
Choose a reason for hiding this comment
8000 The reason will be displayed to describe this comment to others. Learn more.
This notation is not understood by all tools yet. I think the current type is precise enough.
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.
TIL the list pseudo-type 😄 and optional keys.
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.
https://psalm.dev/r/0e971e1c02 but for some reason it doesn't like it :D
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.
You can't use @template
for this (as that's a generic and implies the return type), you need to define a custom type instead but Pslam doesn't support this it seems.
I only use PHPStan atm because Psalm doesn't support PHP 8 yet 😞
Thank you @Warxcell. |
FYI @nicolas-grekas: This change seems to confuse our patch-types script: https://github.com/symfony/symfony/runs/3068884172#step:7:17 |
Fixes
Method getSubscribedEvents() return type has no value type specified in iterable type array.
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type