Improve support for arrow functions / sync with phpcs 3.5.5#79
Merged
jrfnl merged 5 commits intoFeb 11, 2020
Merged
Conversation
... to retrieve the tokens which can represent the arrow function keyword. Includes unit tests.
... in all applicable places.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up on #77.
This PR improves the support for arrow functions by:
PHPCSUtils\Tokens\Collections::arrowFunctionTokensBC()method to retrieve the relevant tokens for the arrow function keyword in a PHPCS cross-version compatible manner.FunctionDeclarations::isArrowFunction()andFunctionDeclarations::getArrowFunctionOpenClose()to give more informative results.Previously, they would follow the tokenization to
T_FNas 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.FunctionDeclarations::getArrowFunctionOpenClose()method toarray|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
falseif 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()andFunctionDeclarations::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 fromarraytoarray|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
falsewhen 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
FunctionDeclarations::getArrowFunctionOpenClose()function.falseor a array with all indexes set to the relevant stack pointers.RuntimeExceptionfor theFunctionDeclarations::getParameters()and theFunctionDeclarations::getProperties()methods.This is no longer needed.
Includes a few additional unit tests to safeguard cross-version compatibility with PHPCS 3.5.3 and 3.5.4.