Closed LastDragon-ru closed 1 month ago
@LastDragon-ru Thank you for reporting this. Definitely a bug in the 3.10.0 release and definitely related to named parameters. Unfortunate that nobody caught this during the testing period.
Minimal code sample it can be reproduced with:
preg_split($r, $h, flags: PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
Symptom: close parenthesis of the function call gets incorrectly tokenized as T_TYPE_CLOSE_PARENTHESIS
.
Also note: it's only the close parenthesis, the open parenthesis is not affected.
2 | L3 | C 1 | CC 0 | ( 0) | T_STRING | [ 10]: preg_split
3 | L3 | C 11 | CC 0 | ( 0) | T_OPEN_PARENTHESIS | [ 1]: (
4 | L3 | C 12 | CC 0 | ( 1) | T_VARIABLE | [ 2]: $r
5 | L3 | C 14 | CC 0 | ( 1) | T_COMMA | [ 1]: ,
6 | L3 | C 15 | CC 0 | ( 1) | T_WHITESPACE | [ 1]: ⸱
7 | L3 | C 16 | CC 0 | ( 1) | T_VARIABLE | [ 2]: $h
8 | L3 | C 18 | CC 0 | ( 1) | T_COMMA | [ 1]: ,
9 | L3 | C 19 | CC 0 | ( 1) | T_WHITESPACE | [ 1]: ⸱
10 | L3 | C 20 | CC 0 | ( 1) | T_PARAM_NAME | [ 5]: flags
11 | L3 | C 25 | CC 0 | ( 1) | T_COLON | [ 1]: :
12 | L3 | C 26 | CC 0 | ( 1) | T_WHITESPACE | [ 1]: ⸱
13 | L3 | C 27 | CC 0 | ( 1) | T_STRING | [ 19]: PREG_SPLIT_NO_EMPTY
14 | L3 | C 46 | CC 0 | ( 1) | T_WHITESPACE | [ 1]: ⸱
15 | L3 | C 47 | CC 0 | ( 1) | T_TYPE_UNION | [ 1]: |
16 | L3 | C 48 | CC 0 | ( 1) | T_WHITESPACE | [ 1]: ⸱
17 | L3 | C 49 | CC 0 | ( 1) | T_STRING | [ 24]: PREG_SPLIT_DELIM_CAPTURE
18 | L3 | C 73 | CC 0 | ( 0) | T_TYPE_CLOSE_PARENTHESIS | [ 1]: )
19 | L3 | C 74 | CC 0 | ( 0) | T_SEMICOLON | [ 1]: ;
I'll have a look.
@LastDragon-ru @momala454 PR #507 should fix this. I would appreciate it if you could test the fix.
If you need it, you can download the PHAR files containing the patch here: https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/runs/9173810442
It fixes the problem, thanks
Thanks for testing @momala454!
Yep, no error anymore
Thanks @LastDragon-ru for testing and confirming!
Sorry, I'm not sure this is related to phpcs or slevomat, so I've posted it in both repos 🤷♂️
https://github.com/slevomat/coding-standard/issues/1680
Describe the bug
Since phpcs v3.10.0 the code generate false positive errors about unused constants. Seems it is caused by named arg (no error without it).
Code sample
Custom ruleset
Expected behavior
No errors.