phpmd icon indicating copy to clipboard operation
phpmd copied to clipboard

UnusedPrivateField false positive with Trait

Open alexz707 opened this issue 6 years ago • 0 comments

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

alexz707 avatar Apr 25 '19 08:04 alexz707