-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Undefined Offset notice during live coding of arrow functions #2805
Undefined Offset notice during live coding of arrow functions #2805
Conversation
56a04a6
to
332e094
Compare
…ow functions Defensive coding for the arrow functions backfill. This fixes a number of "undefined index" PHP notices when arrow functions are being declared during live coding. ``` Notice: Undefined offset: 561 in /path/to/PHP_CodeSniffer/src/Tokenizers/PHP.php on line 1807 Notice: Undefined offset: 561 in /path/to/PHP_CodeSniffer/src/Tokenizers/PHP.php on line 1808 Notice: Undefined offset: 561 in /path/to/PHP_CodeSniffer/src/Tokenizers/PHP.php on line 1815 ``` It also fixes a bug where an inner for loop was using the wrong variable for the condition part. Includes adjusted unit test + additional unit test covering all changes. Includes minor documentation fix.
@@ -1812,7 +1812,7 @@ protected function processAdditional() | |||
} | |||
} | |||
|
|||
if ($this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) { | |||
if (isset($this->tokens[$x]) === true && $this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isset Always returns bool
. === true
is redundant and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tvanrielwendrich While that is true, the PHPCS native code style rules demands the === true
, so no, this cannot be removed.
Thanks |
Defensive coding for the arrow functions backfill. This fixes a number of "undefined index" PHP notices when arrow functions are being declared during live coding.
It also fixes a bug where an inner for loop was using the wrong variable for the condition part.
Includes unit test.