php:S1144 False positive first class callable

PHP 8.1 (8.2.8 in use) provides new syntax - first class callable. Newest SonarQube 9.9 provides its support, but I get false positive php:S1144 actually.

I am using the newest version SonarQube Community Edition 9.9.1 at the moment.

public function configureContainer(Container $container): void
{
    $container->bindSingleton(
        SomeInterface::class,
        $this->createSome(...)
    );
}

private function createSome(): SomeInterface // php:S1144
{
    return new Some();
}

image

Hi @kordum
Thanks for this report!

You are correct, this is a false positive and we should not raise an issue. It seems that we are not taking the methods in the first class callable into account in this rule.

I’ve created a ticket to fix this issue, which will be tackled in the next development iteration of the PHP Analyzer.

Thanks for the contribution,
Jonas

1 Like