Improve support for arrow functions / sync with phpcs 3.5.5 #79
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_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.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
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()
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 fromarray
toarray|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
FunctionDeclarations::getArrowFunctionOpenClose()
function.false
or a array with all indexes set to the relevant stack pointers.RuntimeException
for 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.