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

Wrong end of statement for fn closures #2748

Closed
michalbundyra opened this issue Dec 6, 2019 · 0 comments · Fixed by #2749
Closed

Wrong end of statement for fn closures #2748

michalbundyra opened this issue Dec 6, 2019 · 0 comments · Fixed by #2749
Milestone

Comments

@michalbundyra
Copy link
Contributor

Example code:

<?php

$a = function () {};

$b = fn ($a) => $a;

return 1;

Tokens:

00: T_OPEN_TAG => <?php\n
01: T_WHITESPACE => \n
02: T_VARIABLE => $a
03: T_WHITESPACE => ·
04: T_EQUAL => =
05: T_WHITESPACE => ·
06: T_CLOSURE => function
07: T_WHITESPACE => ·
08: T_OPEN_PARENTHESIS => (
09: T_CLOSE_PARENTHESIS => )
10: T_WHITESPACE => ·
11: T_OPEN_CURLY_BRACKET => {
12: T_CLOSE_CURLY_BRACKET => }
13: T_SEMICOLON => ;
14: T_WHITESPACE => \n
15: T_WHITESPACE => \n
16: T_VARIABLE => $b
17: T_WHITESPACE => ·
18: T_EQUAL => =
19: T_WHITESPACE => ·
20: T_FN => fn
21: T_WHITESPACE => ·
22: T_OPEN_PARENTHESIS => (
23: T_VARIABLE => $a
24: T_CLOSE_PARENTHESIS => )
25: T_WHITESPACE => ·
26: T_FN_ARROW => =>
27: T_WHITESPACE => ·
28: T_VARIABLE => $a
29: T_SEMICOLON => ;
30: T_WHITESPACE => \n
31: T_WHITESPACE => \n
32: T_RETURN => return
33: T_WHITESPACE => ·
34: T_LNUMBER => 1
35: T_SEMICOLON => ;
36: T_WHITESPACE => \n

Test:

$phpcsFile->findEndOfStatement(4); // result 13 - correct
$phpcsFile->findEndOfStatement(18); // result 35 - incorrect, expected 29
michalbundyra added a commit to michalbundyra/Squizlabs_PHP_CodeSniffer that referenced this issue Dec 6, 2019
michalbundyra added a commit to michalbundyra/coding-standard that referenced this issue Dec 8, 2019
… a bug

The function File::findEndOfStatement has a bug in finding end of statement
for fn closures, see: squizlabs/PHP_CodeSniffer#2748
@gsherwood gsherwood added this to the 3.5.4 milestone Dec 8, 2019
michalbundyra added a commit to michalbundyra/coding-standard that referenced this issue Oct 16, 2024
…is fixed

Related issue squizlabs/PHP_CodeSniffer#2748 has been merged and deployed, and we are now using version where the fix is present, so there is no longer need for the custom code, and it is removed now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants