Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 22, 2025

PHP_CodeSniffer originally offered a number of "token groups" as static properties in the Tokens class to allow re-use of these groups across sniffs.
As of PHP_CodeSniffer 4.0.0, these static properties still exist, but are now (soft) deprecated in favour of class constants in the Tokens class for the same, which should create more stability, as this means the token groups can no longer be changed from within a(n external) sniff.

PHP_CodeSniffer related projects which still support both PHPCS 3.x as well as 4.x, will, for the time being, still need to use the static properties from the Tokens class.

Once a PHP_CodeSniffer related project has dropped support for PHPCS 3.x though, they can enforce the use of the class constants from the Tokens class by running this re-usable workflow in their CI.

  • This workflow is particularly useful for repositories which have existing open PRs at the time of the PHPCS version drop and these open PRs should not re-introduce references to the static properties.
  • This workflow can also be helpful for repositories which have contributors which contribute to a range of PHPCS related repos and for whom it would be very easy to overlook that they've used the "old-school" token group instead of the new-fangled token group constants.

In contrast to most of the other reusable workflows, this workflow does not work based on a configuration file.
One should only add a job calling this workflow to a project's CI once support for PHPCS 3.x has been dropped.

Includes adding documentation about this workflow to the README file.

PHP_CodeSniffer originally offered a number of "token groups" as static properties in the `Tokens` class to allow re-use of these groups across sniffs.
As of PHP_CodeSniffer 4.0.0, these static properties still exist, but are now (soft) deprecated in favour of class constants in the `Tokens` class for the same, which should create more stability, as this means the token groups can no longer be changed from within a(n external) sniff.

PHP_CodeSniffer related projects which still support both PHPCS 3.x as well as 4.x, will, for the time being, still need to use the static properties from the `Tokens` class.

Once a PHP_CodeSniffer related project has dropped support for PHPCS 3.x though, they can enforce the use of the class constants from the `Tokens` class by running this re-usable workflow in their CI.

* This workflow is particularly useful for repositories which have existing open PRs at the time of the PHPCS version drop and these open PRs should not re-introduce references to the static properties.
* This workflow can also be helpful for repositories which have contributors which contribute to a range of PHPCS related repos and for whom it would be very easy to overlook that they've used the "old-school" token group instead of the new-fangled token group constants.

In contrast to most of the other reusable workflows, this workflow does not work based on a configuration file.
One should only add a job calling this workflow to a project's CI once support for PHPCS 3.x has been dropped.

Includes adding documentation about this workflow to the `README` file.
@jrfnl jrfnl added this to the 1.1.0 milestone Dec 22, 2025
@jrfnl jrfnl requested a review from fredden December 22, 2025 17:31
@jrfnl
Copy link
Member Author

jrfnl commented Dec 22, 2025

Note: the "Markdown" workflow failure can be ignored - this is due to the documentation in the README file referencing the new workflow file, while that file doesn't yet exist on the main branch ;-)

@fredden fredden enabled auto-merge (rebase) December 23, 2025 21:51
@jrfnl jrfnl disabled auto-merge December 23, 2025 22:11
@jrfnl jrfnl merged commit a06ac9f into main Dec 24, 2025
9 of 11 checks passed
@jrfnl jrfnl deleted the feature/new-reusable-workflow-token-constants branch December 24, 2025 17:52
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.

3 participants