You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I think my team found an issue with the SwitchDeclaration sniffer. This happens when we try to define a SWITCH statement inside an anonymous function inside a ternary operator.
Here is a script with examples:
Running this code against latest version of phpcs returns errors:
$ php --version
PHP 7.2.24 (cli) (built: Oct 22 2019 11:15:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
$ vendor/bin/phpcs --standard=PSR2 test_file.php
FILE: test_file.php
-------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
-------------------------------------------------------------------------------------------------------
1 | WARNING | A file should declare new symbols (classes, functions, constants, etc.) and cause no
| | other side effects, or it should execute logic with side effects, but should not do
| | both. The first symbol is defined on line 34 and the first side effect is on line 6.
10 | ERROR | CASE statements must be defined using a colon
42 | ERROR | CASE statements must be defined using a colon
-------------------------------------------------------------------------------------------------------
Time: 103ms; Memory: 6MB
Please advice if you need further information. Thank you.
The text was updated successfully, but these errors were encountered:
The problem here lies in the tokenizer. It is tokenzing the first T_COLON in the switch statement as T_INLINE_ELSE because it thinks it is in an inline condition.
gsherwood
changed the title
PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase Error on specific format
Case statements not tokenized correctly when switch is contained within ternary
Dec 16, 2019
Hello, I think my team found an issue with the SwitchDeclaration sniffer. This happens when we try to define a SWITCH statement inside an anonymous function inside a ternary operator.
Here is a script with examples:
Running this code against latest version of phpcs returns errors:
Please advice if you need further information. Thank you.
The text was updated successfully, but these errors were encountered: