Skip to content

Incorrect: Class referenced with incorrect case, #14205

@AnneSmids

Description

@AnneSmids

Bug report

I import:

use App\Service\Competitie\Team\SamenstellingService as TeamSamenstellingService;

PHPStan reports:

Class App\Service\Competitie\Team\TeamsamenstellingService referenced with incorrect case:
App\Service\Competitie\Team\TeamSamenstellingService.

However:

TeamSamenstellingService is an alias for SamenstellingService.

TeamsamenstellingService is a different class.

That class is not used in this file.

It appears PHPStan resolves the alias name against the similarly named class and incorrectly reports a case mismatch.

Code snippet that reproduces the problem

https://phpstan.org/r/d01b7949-c3f5-41d3-bf48-054eee28c563

Expected output

When importing a class using an alias:

use App\Service\Competitie\Team\SamenstellingService as TeamSamenstellingService;

PHPStan should:

Resolve TeamSamenstellingService strictly as an alias of
App\Service\Competitie\Team\SamenstellingService

Not attempt to match the alias name against other classes in the same namespace

Not report a class.nameCase error unless the aliased target class itself has an incorrect case

In this situation:

SamenstellingService and TeamsamenstellingService are two distinct classes.

The alias TeamSamenstellingService intentionally refers to SamenstellingService.

TeamsamenstellingService is not referenced in this file.

Therefore, no case-mismatch error should be reported.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan helps us a lot to detect issues in our code early! So they will not break on production and gives us less stress. So thank you a lot for working on PHPStan

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions