Skip to content
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

Compatibility with PHPCS 4.0 #71

Open
2 of 5 tasks
jrfnl opened this issue Jan 31, 2020 · 1 comment
Open
2 of 5 tasks

Compatibility with PHPCS 4.0 #71

jrfnl opened this issue Jan 31, 2020 · 1 comment

Comments

@jrfnl
Copy link
Member

jrfnl commented Jan 31, 2020

This is just a ticket to keep track of the changes which PHPCSUtils will need to account for by the time PHPCS 4.0 comes out.

No urgency until there is sight of a release date.

As a principle, the code in PHPCSUtils should work with PHPCS 4.x. External standard shouldn't need to do anything special if they only want to support PHPCS 4.x
If external standards want to continue to support PHPCS 3.x as well a PHPCS34Utils standard should be added to provide the compatibility layer, where necessary.

To do:

  • Work-around/account for the removal of the PHCPS native T_ARRAY_HINT and T_RETURN_TYPE tokens. squizlabs/PHP_CodeSniffer@8cba000
    Possible solution direction:

    • Add a PHPCS34Utils standard similar to the principle of PHPCS23Utils to create the BC layer.
    • Remove the tokens from the static arrays in PHPCSUtils\Tokens\Collections.
    • In a __construct() method for the PHPCS34Utils sniff, add them back to the static Collections arrays if PHPCS < 4.x is detected.
    • For all other places these are used (if any), wrap them within a defined() check.

    Other possible solution direction:

    • Have a PHPCS34Utils standard without any sniffs, but just with an <autoload> directive.
    • In a phpcs34-autoload.php file add the tokens back if they don't exist yet, but make sure that the PHP_CodeSniffer\Util\Tokens file is loaded first to prevent "constant already defined" notices.
      (IIRC PHPCS itself doesn't wrap PHPCS native tokens in a if (defined()).)
  • Closure use tokens will be parenthesis owners in PHPCS 4.x
    squizlabs/PHP_CodeSniffer@08824f3
    This affects at least the following:

    • BCTokens::ParenthesisOpeners()
    • The BCFile::getMethodParameters()/FunctionDeclarations::getParameters() methods.
    • The BCFile::isReference()/Operators::isReference() methods.
    • UseStatements::getType()

Probably won't have any influence/impact on PHPCSUtils. Needs verification:

  • Removal of the support for "old-style" (pre PHPCS 3.2.0) ignore comments. squizlabs/PHP_CodeSniffer@86e7465
  • Removal of the support for "old style" (pre PHPCS 3.3.0) array properties in rulesets. squizlabs/PHP_CodeSniffer@8b5408c
  • Verify that any JS/CSS specific code doesn't start throwing errors now the tokenizers have been removed.
    PHPCSUtils does not purposefully support JS/CSS anyway, but the backcompat functions and sister-functions for those in PHPCSUtils may have inherited support based on the PHPCS 2.x/3.x implementation.
    squizlabs/PHP_CodeSniffer@ea52e7b

Other notes (no sight yet of what the impact will be, if any):

  • PHPCS 4.x will drop support for PHP 5.
  • PHPCS 4.x will drop support for installation via PEAR.
@jrfnl
Copy link
Member Author

jrfnl commented Mar 26, 2020

PRs already pulled & merged related to this issue: #109, #110, #111, #112, #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant