UnusedPrivateField false positive with Trait
Open
@kylekatarnls is already working on this.
Since May 21, 2020.
- Dominant language
- PHP
- Stars
- 2.5k
- Forks
- 361
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 11
Description
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:
<?php
trait TestTrait {
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.