Skip to content

[DI] Always consider abstract getters as autowiring candidates #21602

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

Merged
merged 1 commit into from
Feb 27, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Feb 13, 2017

Q A
Branch? master
Bug fix? no
New feature? yes (a missing part of getter autowiring really)
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

When a definition is set to be autowired with no method explicitly configured, we already wire the constructor.
We should also autowire abstract getters - with the same reasoning that makes us autowire the constructor: without concrete getters, the class is unusable. This just makes it usable again.

@nicolas-grekas
Copy link
Member Author

now with tests

@@ -478,7 +482,7 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint)
$this->populateAvailableType($argumentId, $argumentDefinition);

try {
$this->processValue($argumentDefinition, true);
$this->processValue($argumentDefinition, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just omit the argument entirely

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, done

@stof
Copy link
Member

stof commented Feb 14, 2017

👍
Status: reviewed

@@ -21,8 +21,11 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class GetterOverriding
abstract class GetterOverriding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should you add another test instead of editing this one to be sure that both cases are covered?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test case splitted

@@ -159,6 +159,10 @@ private function getMethodsToAutowire(\ReflectionClass $reflectionClass, array $
continue 2;
}
}

if ($reflectionMethod->isAbstract() && !$reflectionMethod->getNumberOfParameters()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check all conditions making it eligible to autowiring (return type...).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that won't provide anything more to me since those checks are going to happen anyway later on

@dunglas
Copy link
Member

dunglas commented Feb 14, 2017

👍

@nicolas-grekas nicolas-grekas force-pushed the di-getter-autow branch 4 times, most recently from c984198 to 61ea411 Compare February 14, 2017 15:18
@fabpot
Copy link
Member

fabpot commented Feb 27, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 8f246bd into symfony:master Feb 27, 2017
fabpot added a commit that referenced this pull request Feb 27, 2017
…ates (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Always consider abstract getters as autowiring candidates

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes (a missing part of getter autowiring really)
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

When a definition is set to be autowired with no method explicitly configured, we already wire the constructor.
We should also autowire abstract getters - with the same reasoning that makes us autowire the constructor: without concrete getters, the class is unusable. This just makes it usable again.

Commits
-------

8f246bd [DI] Always consider abstract getters as autowiring candidates
@nicolas-grekas nicolas-grekas deleted the di-getter-autow branch February 28, 2017 08:48
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.

5 participants