phpsonarqubepsr-2

SonarQube: Message displayed in PHP code


I have this statement:

return ++$maxContratNum;

SonarQube display this message:

Extract this increment or decrement operator into a dedicated statement

what's meaning this message ??

Thank you


Solution

  • The message is trying to tell you to write like this:

    ++$maxContratNum;
    return $maxContratNum;
    

    Written this way, it's perfectly clear that the value of $maxContratNum is incremented, and the function returns that incremented value.

    If you write return ++$maxContratNum;, that may be confusing to some readers.