phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
12.91k stars 879 forks source link

class.nameCase error is not reported when the wrong case is just in return type #11470

Open JanTvrdik opened 2 months ago

JanTvrdik commented 2 months ago

Bug report

class.nameCase error is not reported when the correct case is used in use statement and wrong case is used in return type

Code snippet that reproduces the problem

https://phpstan.org/r/13cacbc4-8d7a-4e8f-8f0f-79afa8aa55af

Expected output

Class DateTimeImmutable referenced with incorrect case: dateTimeImmutable.

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

No response

ondrejmirtes commented 2 months ago

The code to report that is there in FunctionDefinitionCheck, so it's gonna definitely be something tricky...

Bellangelo commented 2 months ago

I managed to make some progress on this but I am not sure if this is the correct way. PHPParser stores the original name in the attributes, so it is pretty easy to use it in case it exists. Also, PHPParser has a replaceNodes options which if you disable it also fixes the issue. The problem with this option is that it breaks a lot of tests if you disable it and, of course, you might not need it disabled all the time. Source: https://github.com/nikic/PHP-Parser/blob/master/doc/component/Name_resolution.markdown