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

Improve support for arrow functions / sync with phpcs 3.5.5 #79

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 11, 2020

Follow up on #77.

This PR improves the support for arrow functions by:

  • Adding a PHPCSUtils\Tokens\Collections::arrowFunctionTokensBC() method to retrieve the relevant tokens for the arrow function keyword in a PHPCS cross-version compatible manner.
  • Improving the FunctionDeclarations::isArrowFunction() and FunctionDeclarations::getArrowFunctionOpenClose() to give more informative results.
    Previously, they would follow the tokenization to T_FN as per PHPCS 3.5.4.
    Now they will only return true / an array with the token pointers when the token passed actually represents an arrow function keyword token.
    • Includes changing the return type of the FunctionDeclarations::getArrowFunctionOpenClose() method to array|false.
      Previously the method would return either an empty array or an array with the four indexes set to either the found token pointers or false.
      Now the method will return false if the token passed is not an actual arrow function, or an array with all four indexes set to the relevant token pointers if it is.

This syncs the behaviour of these functions with the tokenization of arrow functions in PHPCS 3.5.5.

Commit summary

Tokens\Collections: add new arrowFunctionTokensBC() method

... to retrieve the tokens which can represent the arrow function keyword.

Includes unit tests.

Implement use of the new Collections::arrowFunctionTokensBC() method

... in all applicable places.

FunctionDeclarations::getArrowFunctionOpenClose(): move fixed array to property

FunctionDeclarations::isArrowFunction()/getArrowFunctionOpenClose(): sync with PHPCS 3.5.5

This brings the FunctionDeclarations::isArrowFunction() and FunctionDeclarations::getArrowFunctionOpenClose() functions in line with the changes in PHPCS which will be released in PHPCS 3.5.5.

Note: the return value for the FunctionDeclarations::getArrowFunctionOpenClose() function has changed from array to array|false.
Previously, the function may return an empty array or an array with only some of the indexes set to false.
Now it will return false when this is not an arrow function or an array with all the indexes set to the relevant stack pointers when it is an arrow function.

This should make the function return value easier to work with.

Includes extensive additional unit tests, as well as some changed unit tests, similar to the additional unit tests as pulled to PHPCS itself for these changes.

Related upstream commits:

Related upstream issues/PRs:

Improve on previous arrow function implementation in various utilities

  • Change checking of the return value of the FunctionDeclarations::getArrowFunctionOpenClose() function.
    • This function now either returns false or a array with all indexes set to the relevant stack pointers.
  • Improved the message of the RuntimeException for the FunctionDeclarations::getParameters() and the FunctionDeclarations::getProperties() methods.
  • Update unit tests to reflect the change in tokenization of "fn" tokens.
  • Remove test skipping for select arrow function related tests on select PHP/PHPCS versions.
    This is no longer needed.
  • Add/improve documentation about arrow function support.

Includes a few additional unit tests to safeguard cross-version compatibility with PHPCS 3.5.3 and 3.5.4.

... to retrieve the tokens which can represent the arrow function keyword.

Includes unit tests.
…sync with PHPCS 3.5.5

This brings the `FunctionDeclarations::isArrowFunction()` and `FunctionDeclarations::getArrowFunctionOpenClose()` functions in line with the changes in PHPCS which will be released in PHPCS 3.5.5.

Note: the return value for the `FunctionDeclarations::getArrowFunctionOpenClose()` function has changed from `array` to `array|false`.
Previously, the function may return an empty array or an array with only some of the indexes set to `false`.
Now it will return `false` when this is not an arrow function or an array with all the indexes set to the relevant stack pointers when it _is_ an arrow function.

This should make the function return value easier to work with.

Includes extensive additional unit tests, as well as some changed unit tests, similar to the additional unit tests as pulled to PHPCS itself for these changes.

Related upstream commits:
* squizlabs/PHP_CodeSniffer@2e3a010
* squizlabs/PHP_CodeSniffer@ea810a2
* squizlabs/PHP_CodeSniffer@2adcb64
* squizlabs/PHP_CodeSniffer@3a62dd4
* squizlabs/PHP_CodeSniffer@6070b60

Related upstream issues/PRs:
* squizlabs/PHP_CodeSniffer 2523
* squizlabs/PHP_CodeSniffer 2859
* squizlabs/PHP_CodeSniffer 2860
* squizlabs/PHP_CodeSniffer 2863
* Change checking of the return value of the `FunctionDeclarations::getArrowFunctionOpenClose()` function.
    - This function now either returns `false` or a array with all indexes set to the relevant stack pointers.
* Improved the message of the `RuntimeException` for the `FunctionDeclarations::getParameters()` and the `FunctionDeclarations::getProperties()` methods.
* Update unit tests to reflect the change in tokenization of "fn" tokens.
* Remove test skipping for select arrow function related tests on select PHP/PHPCS versions.
    This is no longer needed.
* Add/improve documentation about arrow function support.

Includes a few additional unit tests to safeguard cross-version compatibility with PHPCS 3.5.3 and 3.5.4.
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