PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Modernize: add constant visibility

Open jrfnl opened this issue 8 months ago • 0 comments

Description

Constant visibility is available in PHP since PHP 7.1. This commit adds the visibility to all class constants currently in the codebase and starts enforcing constant visibility being required.

In most cases, the visibility remains the same as before, i.e. public, however, there are a couple of exceptions, which could be considered a breaking change:

  • PHP_CodeSniffer\Generators\HTML::STYLESHEET (was public, now private)
    • Even though the class is not final, the Config only allows for requesting a PHPCS native Generator class, so the chances of the class being extended are very slim.
    • On top of that, this was a function local variable until a few months ago, so chances of any external access to the constant being active are also slim based on the timing.
  • PHP_CodeSniffer\Util\Timing::MINUTE_IN_MS and PHP_CodeSniffer\Util\Timing::SECOND_IN_MS (were public, now private)
    • These properties were introduced about six months ago and only ever intended for use by the class itself.

Aside from the above, there are some visibility changes for class constants which are part of the PHPCS native test suite, so not in the public API.

Suggested changelog entry

Changed:

  • The PHP_CodeSniffer\Generators\HTML::STYLESHEET, PHP_CodeSniffer\Util\Timing::MINUTE_IN_MS and PHP_CodeSniffer\Util\Timing::SECOND_IN_MS class constants are no longer public.

jrfnl avatar Apr 26 '25 11:04 jrfnl