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!