Open cs278 opened 2 weeks ago
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
The documentation isn't conflicting. We simply shouldn't report this error when PHPStan encounters a private method/property/constant AND the class in question uses a 3rd party trait we do not analyse.
For now you can ignore this error: https://phpstan.org/user-guide/ignoring-errors
Or maybe even better - write an extension that silences this error for classes that use the trait in question: https://phpstan.org/developing-extensions/always-read-written-properties
Yes I've worked around it using a combination of identifier (these are a brilliant improvement BTW @ondrejmirtes) and regex for anyone else with the same problem:
parameters:
ignoreErrors:
-
message: '/::\$someProperty\b/'
identifier: property.onlyWritten
The documentation isn't conflicting.
Might be question of interpretation, traits are compiler time copy and paste so vendor code gets combined with my code. But I also can't fix any problems in them so yeah, I can see why it might not be ideal to analyse them. I still think it might be worth calling out more prominently somewhere.
We simply shouldn't report this error when PHPStan encounters a private method/property/constant AND the class in question uses a 3rd party trait we do not analyse.
Could that be refined to ignore only those method/property/contstants that are also defined by a used trait? Otherwise you effectively lose "unused privates" reporting for any class that uses a vendor trait.
Bug report
I'm experiencing a problem whereby PHPStan reports falsely that a property is never used, the property is used in methods provided by a vendor trait.
Code/output
```phpIt's not possible to replicate this on phpstan.org/try, eventually I found a blog post explaining the problem: https://phpstan.org/blog/how-phpstan-analyses-traits.
So my understanding is PHPStan doesn't fully analyse any of my code that use vendor traits, so I need to include vendor traits in the analysis. However this directly conflicts with the getting started guide which states:
Including vendor traits (by their path) into the analysis is also complicated by the fact there is no guarantee that the trait will be the only thing in the source file - forcing the user to analyse vendor code they cannot fix or even care about.
Even though the way PHPStan works with traits is surprising I expect it's not without good reason, is there anything that can be done to improve this? A few thoughts:
Code snippet that reproduces the problem
N/A
Expected output
No error reported
Did PHPStan help you today? Did it make you happy in any way?
No response