php:S1764 False negative with exponent operator (**)

Greetings people!

First time reporting something here so I apologize if this is a duplicate (didn’t find an existing one already).

Issue
False negative when using PHP exponent operator (**)

Rules

PHP S1764: Identical expressions should not be used on both sides of a binary operator

Environment
SonarQube: Community Edition, Version 9.9 (build 65466)

Code snippet

// First case: using scalars
$foo = 3 ** 3;

// Second case: using variables
$bar = $foo ** $foo;

Context
For various reasons, my company have processes that use exponent values.
They can be either class constants (in which case we use integers) or resulting from dynamic values (then we use variables).

This looks like a false negative to me, in the same way it was for the shift << operator. Sure, it could lead to overflow value but this is the developer’s responsibility to check for it.

For now we switched to using pow() function. Still, I wondered if this use-case could lead to an exception in the rule?

Nice day to you!

Hello @Ikau and welcome to the community!

I believe you are correct, this is a false positive, and it hasn’t been reported before. While this may be considered as the result of an error, this code looks much more valid to me than using the same operand in logical operations.

I created a ticket, you can subscribe to updates. We will tackle the ticket in one of the next sprints on the PHP analyzer.

Best,

Peter