Sonar PHP extending the "UnusedFunctionParametersCheck" check

Hi,

Currently I’m trying to make SonarQube able to integrate more seamlessly with Magento (2). An example of something I’m trying to resolve is a false-positive “UnusedFunctionParametersCheck” issue in case of a Magento plugin.

Our Use-Case
A plugin in Magento is a method with before, after or around as its prefix and after that the method name to “intercept”, for example, a method execute could have a plugin beforeExecute, afterExecute and aroundExecute.

In case of the mentioned types of plugins the first argument is always the “subject”, the class where the execute method is declared. $subject is not always used, but because SonarQube doesn’t know about plugins in Magento and how they work it will create a false-positive issue to remove the “unused method parameter”.

Question
I want to extend the original “UnusedFunctionParametersCheck” to accommodate the above mentioned use-case.

I seem to have 2 options but I’d like there to be a third because I really don’t like the two I came up with.

  • Fork the “sonar-php” repository and make my changes in there, this doesn’t really seem right because the “sonar-php” repository should target PHP and not a specific framework (use-case).
  • Copy-paste the original “UnusedFunctionParametersCheck” and disable the one in the “sonar-php” plugin.

Is there a way for me to possibly remove issues that another rule added, so that I keep the original “UnusedFunctionParametersCheck” but afterwards I run my own rule which might or might not remove issues created by the “UnusedFunctionParametersCheck”?

Hi,

Option 1 “Fork the sonar-php repository” is not recommended at all.
I’m not sure what your option 2 really means.

What is definitely possible is to create a custom plugin for PHP containing one rule. You can implement that rule by taking a good inspiration from UnusedFunctionParametersCheck. Once you have deployed your custom plugin on your SonarQube server, you can adjust your quality profile so that it contains your custom rule instead of UnusedFunctionParametersCheck.

Other simpler options:

  • Mark issues as false positives. That’s probably not a good solution if you have many issues.
  • Add exclusions for UnusedFunctionParametersCheck for a given file pattern: see “Ignore Issues on Multiple Criteria” in the documentation.

Hi,

Option 2 is basically the option that you suggested with the custom plugin for PHP, but this would require me to copy-paste the original “UnusedFunctionParametersCheck” to retain the original logic of the “UnusedFunctionParametersCheck”.

Thank for your suggestions!