-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX][DependencyInjection] Suggest to write an implementation if the interface cannot be autowired #25547
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
[DX][DependencyInjection] Suggest to write an implementation if the interface cannot be autowired #25547
Conversation
50da469
to
cb333cd
Compare
Isn't this just stating the obvious? |
@nicolas-grekas well, I'd say so as well, but I just saw a developer having this issue; and such message would have helped him. It doesn't cost us anything to phrase it a bit differently and benefits is it helps some :) |
I agree with @sroze people could have this kinds of errors, and doing this help them to develop. |
I like this step. In 3.4, we already create interface aliases if you have a service that implements that interface. So, indeed, it seems like most of the time, the solution would indeed be to simply create a class that implements this interface (then the interface alias would be created and it would autowire). So, talking this through, yea, I think that this recommendation is always correct. So why not? |
8000 | @@ -457,6 +457,10 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label) | ||
} else { | |||
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists'; | |||
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference)); | |||
|
|||
if ($r->isInterface()) { | |||
$message .= ' Did you write an implementation of this interface?'; |
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.
What about:
Did you create a class that implements this interface?
Or:
You may need to create a class that implements this interface.
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.
I like "Did you create a class that implements this interface?"
not true, as the alias is created automatically only if the implementation and the interface are both discovered by the PSR-4 discovery. A third-party interface will not be discovered in |
cb333cd
to
961e3e7
Compare
Updated the message based on @weaverryan's 1st suggestion 👍 |
…on if the interface cannot be autowired (sroze) This PR was merged into the 3.4 branch. Discussion ---------- [DX][DependencyInjection] Suggest to write an implementation if the interface cannot be autowired | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ø | License | MIT | Doc PR | ø This would add a hint for the developers when the interface cannot be wired. This suggests creating the implementation of the interface. **Note:** this is 3.4 because I believe DX should be treated as bugs. **Note 2:** fabbot issue is false positive Commits ------- 961e3e7 Suggest to write an implementation if the interface cannot be autowired
This would add a hint for the developers when the interface cannot be wired. This suggests creating the implementation of the interface.
Note: this is 3.4 because I believe DX should be treated as bugs.
Note 2: fabbot issue is false positive