Skip to content

Commit 3b9282a

Browse files
authored
Fix possible index error in NonExecutableCodeSniff
I was running into this while working on another sniff. One trivial example I found to demonstrate the bug is `<?php return array_map(`. This can happen when PHPCS runs on a file I'm currently typing in, but the file is not complete yet. I believe it's safe to assume the 'parenthesis_closer' array key only exists on T_OPEN_PARENTHESIS tokens, and the 'bracket_closer' key only on T_OPEN_CURLY_BRACKET tokens. I had a quick look at the tokenizer and I believe this is indeed the case. But I might be wrong. Sorry for not providing a test. I would love to, but I'm not familiar enough with the test setup here.
1 parent 75ff420 commit 3b9282a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ public function process(File $phpcsFile, $stackPtr)
211211
break;
212212
}
213213

214-
if ($tokens[$start]['code'] === T_OPEN_PARENTHESIS) {
214+
if (isset($tokens[$start]['parenthesis_closer']) === true) {
215215
$start = $tokens[$start]['parenthesis_closer'];
216216
continue;
217217
}
218218

219-
if ($tokens[$start]['code'] === T_OPEN_CURLY_BRACKET) {
219+
if (isset($tokens[$start]['bracket_closer']) === true) {
220220
$start = $tokens[$start]['bracket_closer'];
221221
continue;
222222
}

0 commit comments

Comments
 (0)