[php][WordPress] Rule about GNU gettext context functions

I’m using WordPress translation functions with text domains (https://developer.wordpress.org/themes/functionality/internationalization/#add-text-domain-to-strings), and it’s flagged as a duplication - I should define a constant to use as a text domain, and that shouldn’t be done, because of how GNU gettext works (https://markjaquith.wordpress.com/2011/10/06/translating-wordpress-plugins-and-themes-dont-get-clever/).

Can I somehow globally disable this, as I have quite a lot of such notices…

Maybe you can use sonar.cpd.exclusions (briefly documented here).
Does that help you?

I’ll test this now. Thanks!

Edit: Doesn’t seem like this will help, as I have the ‘duplicated’ code scattered through the plugin.I would have to provide the paths where these strings happen, and that is basically the entire plugin :confused:

That would be quite radical:
sonar.cpd.exclusions=**/*

Yeah, I’d like to avoid that :confused:

Hi @dingo-d ,

You could create your own PHP profile, and de-activate the “String literals should not be duplicated” rule. This is what the built-in Drupal profile does, for example (as they have a similar situation).

  1. Go to “Quality Profiles”, filter by PHP
  2. Copy (don’t extend) the Sonar way profile (or PSR-2, or even Drupal – but Sonar way has most default rules)
  3. Edit this new profile, search for the “String literals…” rule, and click on Deactivate
  4. Use this new profile for your project, or you can set it as the default for all PHP code

Let us know how that goes.