SonarQube 8.7.0.41497
With PhpStorm SonarLint Plugin
At the moment, we are getting many Unused “private” methods should be removed rule violations on dynamically called methods. And while these are falsely reported in SonarQube and by SonarLint, PhpStorm understands correctly and links usages when used with PHPDoc tags such as @uses or @used-by.
Here’s a simple example of where methods one
and two
are reported as unused by SonarLint but are fine for PhpStorm because @uses
tags are used on a caller method.
class A
{
/**
* @uses one
* @uses two
*/
public function callOther(string $method): void
{
call_user_func([$this, $method]);
// or
$this->{$method}();
}
private function one()
{
return func_get_args();
}
private function two()
{
return func_get_args();
}
}
$a = new A();
$a->callOther('one');
$a->callOther('two');