| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| continue; | ||
| } | ||
|
|
||
| if ($this->isOverridingPrivateTraitMethod($classReflection, $methodName)) { |
There was a problem hiding this comment.
why does $method->isDeclaredInTrait() in line 63 not work?
Sorry, something went wrong.
There was a problem hiding this comment.
I see now, that we have 2 declared methods, and the one in the loop is not declared on the trait but overrides one from the trait
Sorry, something went wrong.
…nused A class member takes precedence over the member of the same name coming from a used trait, so a private method redeclared in the class is what the trait's own methods call. The rule sees those call sites only when the trait is part of the analysed files: analysing a project whose paths do not include its dependencies leaves ClassMethodsNode::getMethodCalls() with no call at all, and the class method is reported as unused. The canonical case is a Symfony application, where the framework recipe generates a Kernel redeclaring KernelTrait::getAllowedEnvs() while the trait lives in vendor/, outside of the analysed paths. Skip those methods. Nothing is left to distinguish an override that the trait calls from one it does not, so a redeclared private method the trait never calls is no longer reported either. Fixes phpstan/phpstan#12201 Assisted-by: Claude Code:claude-opus-5
|
do we have a similar problem for private constants (UnusedPrivateConstantRule) or properties (UnusedPrivatePropertyRule)? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes phpstan/phpstan#12201
Why
A class member takes precedence over the member of the same name coming from a used trait. So a private method redeclared in the class is the one the trait's own methods call.
UnusedPrivateMethodRule sees those call sites only when the trait is part of the analysed files. In a project whose paths exclude its dependencies, ClassMethodsNode::getMethodCalls() collects no call at all. The class method is then reported as unused.
The canonical case is a Symfony application. The recipe generates a Kernel that redeclares KernelTrait::getAllowedEnvs(), and the trait lives in vendor/.
Every new Symfony 8.1 project hits this from level 4 up. ignoreErrors is the only way out.
What
A private method is skipped when a used trait declares a private method of the same name.
getTraits() is enough without recursion. PHP flattens trait composition. getAllowedEnvs() comes from the nested KernelTrait, and the reflection of MicroKernelTrait already reports it.