Skip to content
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

Merged
merged 1 commit into from
Jun 26, 2019

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jun 10, 2019

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.

@derrabus derrabus force-pushed the improvement/dispatcher-type-hints branch 2 times, most recently from 3b8c6b8 to d93f1d0 Compare June 10, 2019 21:02
@@ -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)
Copy link
Member Author

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.

@derrabus derrabus force-pushed the improvement/dispatcher-type-hints branch from d93f1d0 to 2bc9472 Compare June 10, 2019 21:08
@chalasr chalasr added this to the 5.0 milestone Jun 11, 2019
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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?

@derrabus
Copy link
Member Author

Thanks, we can do similar changes in many place I suppose?

Certainly.

Do we have a tool to automate doing so?

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.

@nicolas-grekas
Copy link
Member

Thanks, that'd be great!

@xabbuh
Copy link
Member

xabbuh commented Jun 23, 2019

Should we open an issue with a checklist of what to look for so we can invite the whole community to check all components?

@derrabus derrabus mentioned this pull request Jun 25, 2019
57 tasks
@derrabus
Copy link
Member Author

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.

@fabpot
Copy link
Member

fabpot commented Jun 26, 2019

Thank you @derrabus.

@fabpot fabpot merged commit 2bc9472 into symfony:master Jun 26, 2019
fabpot added a commit that referenced this pull request Jun 26, 2019
…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.
@derrabus derrabus deleted the improvement/dispatcher-type-hints branch June 26, 2019 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants