PHP S1185: False positive with method attributes

Make sure to read this post before raising a thread here:

Inspection S1185 for PHP (Overriding methods should do more than simply call the same method in super class) generates false positive when the child only adds an attribute.

Example:

abstract class BaseFoo {
  public function getFoo(): string { return 'foo'; }
}
class Foo {
  #[\Deprecated]
  public function getFoo(): string { return parent::getFoo(); }
}

(I previously searched for similar topics with S1185 and S1185 attribute)

Attributes can be used for a wild variety of things (validation, dependency injection changes etc…) and you may not be able to use them on the parent class (generated files, external dependencies etc…).

I observe this false positive on:

  • SonarQube Server: Enterprise Edition - v2025.1.1 (104738)
  • SonarQube for IDE: 12.2.2.84629 (PHPStorm)

Hi,

Welcome to the community and thanks for this report!

Your SonarQube Server is stale, but your SonarQube for IntelliJ version is current. Can you reproduce this in SQ4IDE in standalone / not-connected mode?

 
Thx,
Ann

Your SonarQube Server is stale, but your SonarQube for IntelliJ version is current. Can you reproduce this in SQ4IDE in standalone / not-connected mode?

Yes I have the same issue on SQ4IDE that is not binded to a server. I could have specified this on the original post.

Hi,

Thanks for the confirmation, and no worries! :slight_smile:

I’ve flagged this for the language experts.

 
Ann

Hi,

I’ve been trying to reproduce the issue with the provided reproducer code, but no issue is raised when using the latest SonarQube for IDE (v12.4.0.84870). Could you retry the latest plugin version? Also, please make sure to run the analysis in unbinded mode. :slight_smile:

I’m confused, I still observe the issue on my side

With the same SonarQube for IDE version

image

(Note that on this project I’m not connected to a SonarQube server nor a cloud)

Hmm, could you try the reproducer code you provided in isolation and see if that exact code raises an issue? :thinking:

Hmm, could you try the reproducer code you provided in isolation and see if that exact code raises an issue? :thinking:

Oh sorry, I forgot the extends BaseFoo in the original snippet. The snippet should be:

abstract class BaseFoo {
    public function getFoo(): string { return 'foo'; }
}

class Foo extends BaseFoo {
    #[\Deprecated]
    public function getFoo(): string { return parent::getFoo(); }
}

Thanks for providing the full reproducer snippet and the FP report. I’ve investigated the issue and fixed it for the upcoming release. :slight_smile: