RSPEC-1808 Incorrectly demands moving of opening curly brace

  • What language is this for?

PHP

  • Which rule?

RSPEC-1808

  • Why do you believe it’s a false-positive/false-negative?

SQ asks me to move the opening curly brace of an empty function statement (__construct) to the next line.

According to PER section 4.4 Methods and functions a empty statement should be abbreviated to {} and be placed on the same line as the function definition.

If a function or method contains no statements or comments (such as an empty no-op implementation or when using constructor property promotion), then the body SHOULD be abbreviated as {} and placed on the same line as the previous symbol, separated by a space.

  • Are you using

    • SonarQube Community Build, v25.2.0.102705
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

The code example in the standards document should be enough.

class Point
{
    public function __construct(private int $x, private int $y) {}
    
    // ...
}

or

class Point
{
    public function __construct(
      public readonly int $x,
      public readonly int $y,
    ) {}
}

Hello @brother,

Thanks for raising awareness on this topic.

Again I have to agree with you, this is indeed a FP that need to be fixed.
I created this ticket to follow-up on this.

Thank you again for taking the time to report it.

Best,
Rudy

1 Like

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