TomasVotruba / unused-public

Find Unused Public Elements in Your Code
https://tomasvotruba.com/blog/can-phpstan-find-dead-public-methods/
MIT License
151 stars 12 forks source link

Fix false detection when using superclass properties or constants #98

Closed ngmy closed 9 months ago

ngmy commented 10 months ago

This pull request fixes the following bug: When using superclass properties or constants, they are falsely detected as unused.

TomasVotruba commented 9 months ago

Thanks for the feature :+1:

Could you fix the PHPStan CI build?

TomasVotruba commented 9 months ago

Thanks for the suggestion. I'm looking into the feature again, and it promotes a pattern that we fight against.

We want to avoid using false owner class, as public element (even constant) from 2 child-parent classes can have different type and value. Exact real reference should be used instead.

I'll keep the current version we have.

Thanks for understanding :+1:

ngmy commented 9 months ago

Hi,

I would like an example to help me understand the pattern. I may have misunderstood the pattern, but in the following simple example, it appears that an error occurs if the parent and child property or constant types are different: https://onlinephp.io/?s=s7EvyCjg5eLlSs5JLC5WcMvP5-Wq5uXiLChNyslMVkjOzysuUcjMK1Fw9vcLDlGwVTC0RsiCxFUKivILUotKKqFytSDDYMY5JRYppFaUpOal4DK6uKQoMy8dbrp6ojqS-VBJZCsgCmoB&v=8.3.1%2C8.2.14%2C8.1.27%2C8.0.30%2C7.4.33

TomasVotruba commented 9 months ago

Hey, only actual class is counted. Not link through child nor parent class