Skip to content

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

Closed
@kiler129

Description

@kiler129
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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions