Skip to content

Modernize: add constant visibility #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 26, 2025

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.

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.
@jrfnl
Copy link
Member Author

jrfnl commented Apr 29, 2025

Rebased without changes to get past the merge conflict. Merging once the build has passed.

@jrfnl jrfnl force-pushed the phpcs-4.0/feature/constant-visibility branch from 02ebd35 to bdaf11b Compare April 29, 2025 12:56
@jrfnl jrfnl merged commit d12e243 into 4.x Apr 29, 2025
158 checks passed
@jrfnl jrfnl deleted the phpcs-4.0/feature/constant-visibility branch April 29, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant