Skip to content

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jan 9, 2020

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 unit test.

@jrfnl jrfnl force-pushed the feature/tokenizer-bug-php-74-arrow-functions branch 3 times, most recently from 56a04a6 to 332e094 Compare January 10, 2020 04:11
…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.
}

if ($this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) {
if (isset($this->tokens[$x]) === true && $this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) {
Copy link

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.

Copy link
Contributor Author

@jrfnl jrfnl Jan 14, 2020

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.

@gsherwood gsherwood added this to the 3.5.4 milestone Jan 30, 2020
@gsherwood gsherwood changed the title [Hotfix] PHP Tokenizer: fix "undefined offset" notice during live coding / arrow functions Undefined Offset notice during live coding of arrow functions Jan 30, 2020
gsherwood added a commit that referenced this pull request Jan 30, 2020
@gsherwood gsherwood merged commit 332e094 into squizlabs:master Jan 30, 2020
@gsherwood
Copy link
Member

Thanks

@jrfnl jrfnl deleted the feature/tokenizer-bug-php-74-arrow-functions branch January 30, 2020 22:04
tobias-trozowski pushed a commit to tobias-trozowski/PHP_CodeSniffer that referenced this pull request Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants