phpmd
phpmd copied to clipboard
UnusedPrivateField false positive with Trait
Hi! I have discovered that when I use a private variable only in a trait it will give a false positive unused private field warning:
Simplified example:
trait {
public function testIgnore(string $fieldname): bool
{
if (!in_array($fieldname, self::$ignoreFields, true)) {
return true;
}
return false;
}
}
final class Tester
{
use TestTrait;
private static $ignoreFields = ['one', 'two'];
}
This would give the warning: "Avoid unused private field such as '$ignoreFields'"
Using version 2.6.0 Regards Alex