False positive for named parameter alignment in PHP

Regarding the formatting rule for PHP (php:S1808):
"Align all arguments in this list at column “xx”.

When you’re using named parameters in PHP this will complain about argument misalignment when the named parameter is actually aligned on the correct column. I hope this can be either configured or allowed in the future, because we use these everywhere.
As a side note, we’d love to see a rule to say that you should always be using named parameters when a function has more than X arguments.

// Triggers the code smell
$this->someFunction(
    parameterA: $arg1,
    parameterB: $arg2,
);

// Does not trigger the code smell
$this->someFunction(
    $arg1,
    $arg2,
);

// The "fix"
$this->someFunction(
    parameter1:
    $arg1,
    parameter2:
    $arg2,
)
2 Likes

Hi,

Welcome to the community and thanks for this report!

Are you analyzing with SonarCloud? If not, which version of SonarQube (or SonarLint?) are you using?

 
Thx,
Ann

I’m using SonarCloud, also using SonarLint 7.1.1 in PHPStorm.
Also using the GitHub Action (SonarSource/sonarcloud-github-action@master) with no significant config apart from source and coverage report locations.

1 Like

Hi @faylite,

Thank you for your report. Indeed, this is a false positive, and we should not raise an issue. It seems that we are not correctly handling named arguments. I’ve created a ticket to fix this. Thanks for the contribution.

Best,
Nils

How is this not fixed yet?
It is a required standard of PSR in both PHPStan and PHP CS Fixer static analysis tooling.

These false positives appear at every PR and fail the push.

2 Likes

Hello,

This issue makes sonar trigger errors when using PHP Attributes for Doctrine and/or OpenApi.

Even if I agree with Benjamin named argument are great and a rule such as he mention would be useful, named argument is not mandatory.
Except that with PHP Attributes it’s mandatory, is there a plan for this issue

Any update on this? For any project > PHP 8.1 this causes nearly all code smell false positives

1 Like

I increased the priority of the ticket. It will be part of the next sprint.

Best,

4 Likes

+1 on this.

Super annoying to see these false positives since php8.0. Hope you can find a fix for it soon!

+1 on this.

@Nils_Werner I can see that you’ve merged the PR - thanks :slight_smile: Any update on when these changes will be available for sonarcloud customers?

Hello, yes indeed. It’s fixed and released. It will be available in the next SonarCloud deployment as well as in the next SonarLint and SonarQube releases.

Best,

1 Like

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