Skip to content

Commit 92e5a9a

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/CyclomaticComplexity: ensure the sniff bails if scope_closer is not set
Quoting @jrfnl: "Only checking for the scope_opener, when accessing/using both the scope_opener and scope_closer indexes, is probably fine in practical terms. However, the part of the code base which sets these indexes is not sufficiently covered by tests, nor does it document that those indexes will only be set if both can be set, so there may be edge case exceptions" (#684 (comment)). The sniff was already working fine before this change. Checking if `scope_closer` is just an extra precaution to err on the side of caution.
1 parent 2b466f1 commit 92e5a9a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function process(File $phpcsFile, $stackPtr)
6161
$tokens = $phpcsFile->getTokens();
6262

6363
// Ignore abstract and interface methods. Bail early when live coding.
64-
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
64+
if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
6565
return;
6666
}
6767

0 commit comments

Comments
 (0)