Currently PHPCS has two entry points: the phpcs and phpcbf bootstrap files in the bin directory.
Those two files have a similar content:
Include the autoloader.
Instantiate a PHP_CodeSniffer\Runner object.
Run the relevant method in the Runner class (either runPHPCS() or runPHPCBF()).
Handle the exiting with an exit code.
Within the Runner methods, PHPCS subsequently:
Has some guard code for out of memory issues.
Starts the timer.
Does a requirements check
Starts the actual run with everything that comes with it.
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:
Isolate the code for the minimum requirements check into a separate file/class.
Run the minimum requirements check earlier - from within the bootstrap files, before loading the autoloader/any other PHPCS files.
If done correctly, this would effectively only leave the following files which need to be fully PHP cross-version compatible:
The bootstrap files.
The code for the requirements check.
The DeepExitException class.
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:
Test that the requirements check works as intended on PHP < 7.2 and PHP 7.2+.
Safeguard that the relevant files involved in the requirements check are PHP cross-version compatible.
Current Situation
Currently PHPCS has two entry points: the
phpcs
andphpcbf
bootstrap files in thebin
directory.Those two files have a similar content:
PHP_CodeSniffer\Runner
object.Runner
class (eitherrunPHPCS()
orrunPHPCBF()
).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:
DeepExitException
class.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: