Skip to content

Commit

Permalink
Generic/NestingLevel: ensure the sniff bails if scope_closer is not…
Browse files Browse the repository at this point in the history
… 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.

This commit also updates the related code comment to better reflect what
the if condition does.
  • Loading branch information
rodrigoprimo authored and jrfnl committed Dec 10, 2024
1 parent 0d969c9 commit 50216b1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

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

Expand Down

0 comments on commit 50216b1

Please sign in to comment.