-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[EventDispatcher] Add type-hints to EventDispatcherInterface #31984
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
[EventDispatcher] Add type-hints to EventDispatcherInterface #31984
Conversation
3b8c6b8
to
d93f1d0
Compare
@@ -139,7 +139,7 @@ public function hasListeners($eventName = null) | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function addListener($eventName, $listener, $priority = 0) | ||
public function addListener(string $eventName, $listener, int $priority = 0) |
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.
Note: I intentionally did not add callable $listener
because this would cause a call like…
$dispatcher->addListener('some_event', ['Some\Class', 'someMethod']);
… to trigger autoloading for the class name that is passed here. This might have performance implications if we're adding a lot of static listeners.
d93f1d0
to
2bc9472
Compare
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.
Thanks, we can do similar changes in many place I suppose? Do we have a tool to automate doing so?
Certainly.
I'm not aware of any tool that would not require thorough human review after processing the code. This PR was a manual process. I would volunteer to iterate over the components that I'm familiar with and open similar PRs for them, if you're interested. |
Thanks, that'd be great! |
Should we open an issue with a checklist of what to look for so we can invite the whole community to check all components? |
I've created #32179 for this purpose. |
Thank you @derrabus. |
…face (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [EventDispatcher] Add type-hints to EventDispatcherInterface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A This PR adds type-hints to `EventDispatcherInterface` to give it a more php7-like feeling. Adding these type-hints on master should not be a breaking change because we require php 7.2 there, which allows downstream classes/interfaces to remove a type-hint from a method signature. Commits ------- 2bc9472 [EventDispatcher] Add type-hints to EventDispatcherInterface.
This PR adds type-hints to
EventDispatcherInterface
to give it a more php7-like feeling. Adding these type-hints on master should not be a breaking change because we require php 7.2 there, which allows downstream classes/interfaces to remove a type-hint from a method signature.