PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
805 stars 47 forks source link

4.0 | Refactor the requirements check #530

Open jrfnl opened 2 weeks ago

jrfnl commented 2 weeks ago

Current Situation

Currently PHPCS has two entry points: the phpcs and phpcbf bootstrap files in the bin directory.

Those two files have a similar content:

Within the Runner methods, PHPCS subsequently:

Why this is problematic

PHPCS 3.x has a minimum supported PHP version of 5.4. PHPCS 4.x has a minimum supported PHP version of 7.2 and the intention is to selectively modernize the PHPCS codebase to start using features introduced in PHP 5.5 - 7.2.

As part of the requirements check, PHPCS checks the runtime PHP version complies with the minimum supported PHP version.

To allow for this check to run without causing fatal/parse errors before it can alert the end-user of a problem with the minimum supported PHP version, all files loaded up to that point and which are involved in that check (bootstrap files, Autoloader, Runner, DeepExitException classes (as a minimum)) need to be fully PHP cross-version compatible.

As things are at the moment, this means that any file involved in the minimum requirements check cannot be modernized/cannot use PHP 5.5 - 7.2 features as that would cause a parse error, which would break the minimum requirements check before it can alert the end-user of a problem.

Solution

To prevent these type of fatals and still allow for modernizing the codebase with only minimal exceptions, I intend to:

If done correctly, this would effectively only leave the following files which need to be fully PHP cross-version compatible:

The files which need to stay PHP cross-version compatible (minimum PHP version 5.0) should get a clear warning near the top of the file to mark them as such.

Additionally, in the GitHub actions workflows, safeguards should be put in place to:

  1. Test that the requirements check works as intended on PHP < 7.2 and PHP 7.2+.
  2. Safeguard that the relevant files involved in the requirements check are PHP cross-version compatible.