php:S1144 should take into account PHPDoc @uses/@used-by

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');

Hi,

Welcome to the community!

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

8.7 → 8.9.8 → 9.4 (last step optional)

You may find the Upgrade Guide helpful.

If your error persists after upgrade, please come back to us.

 
Ann

Hi @maxslotov,

Indeed we should consider these two tags for the rule. I have created a ticket based on your code example which should address the issue. Thank you for your contribution.

Best,

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.