We use a fresh install of SonarQube 8.4.1 with latest docker-based scanner on our php codebase.
With private constants that are only used as constant array key/value, the constants are reported as unused. I.e. this rule triggers for the two private constants below in the below snippet.
final class Vendor
{
public const PURPOSES = [self::PURPOSE_FUNCTIONAL, self::PURPOSE_ANALYTICAL];
private const PURPOSE_ANALYTICAL = 'analytical';
private const PURPOSE_FUNCTIONAL = 'functional';
// more code that doesn't use those constants
}
We have similar pieces of code, with variants that have constant-based array-keys or where the array is protected rather than public.
We are happy to inform you that we have improved the rule and now the noise described in your example disappears. This improvement was released with SQ 8.6. We would love to hear your feedback.
(Here is the ticket: https://jira.sonarsource.com/browse/SONARPHP-1049)