Skip to content

Commit

Permalink
Generic/CyclomaticComplexity: ensure the sniff bails if `scope_closer…
Browse files Browse the repository at this point in the history
…` 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.
  • Loading branch information
rodrigoprimo authored and jrfnl committed Dec 2, 2024
1 parent 2b466f1 commit 92e5a9a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();

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

Expand Down

0 comments on commit 92e5a9a

Please sign in to comment.