8000 [DIC][DX] Detect case mismatch in autowired service names · Issue #25122 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[DIC][DX] Detect case mismatch in autowired service names #25122

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

Closed
kiler129 opened this issue Nov 22, 2017 · 1 comment
Closed

[DIC][DX] Detect case mismatch in autowired service names #25122

kiler129 opened this issue Nov 22, 2017 · 1 comment

Comments

@kiler129
Copy link
Contributor
kiler129 commented Nov 22, 2017
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 4.x

Currently when someone misspell service name the message suggesting proper spelling is displayed. However when someone puts a correct service name, but the case doesn't match a generic error message is displayed:

Cannot autowire service "AutowiredService": argument "$autowiredParam" of method "__construct()" references class "caseMissmatchService" but no such service exists. It cannot be auto-registered because it is from a different root namespace.

PhpStorm (I don't know about other IDEs) doesn't have case inspection enabled by default, so such error is hard to catch just by looking. I agree autocompletion should be used whenever possible, but such errors still happen for peoples using simple editors.

I suggest improving DX of the AutowirePass to contain more detailed error message when service name is correct but case doesn't match. Class loader already behaves like that:

throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: "%s" vs "%s".', $class, $name));

What do you think?

@kiler129 kiler129 changed the title [DX] Detect case mismatch in autowired service names [DIC][DX] Detect case mismatch in autowired service names Nov 22, 2017
@sroze
Copy link
Contributor
sroze commented Nov 25, 2017

Proposed #25155 to add such behaviour.

nicolas-grekas added a commit that referenced this issue Nov 30, 2017
…Simperfit, sroze)

This PR was merged into the 4.0 branch.

Discussion
----------

[DependencyInjection] Detect case mismatch in autowiring

| Q             | A
| ------------- | ---
| Branch?       | 4.0
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25122
| License       | MIT
| Doc PR        | ø

If there is a case-sensitive typo in the service injection, this will suggest the non-typoed version.

Commits
-------

407f132 Test the suggestion of already registered services
decaf23 [DependencyInjection] Add more information to the message when passing miss matching class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0