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

Undefined Offset notice during live coding of arrow functions #2805

Merged

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.
@@ -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) {
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 Idea Bank in PHPCS v3 Development via automation Jan 30, 2020
@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
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release 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
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants