Skip to content

Commit 50216b1

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/NestingLevel: 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. This commit also updates the related code comment to better reflect what the if condition does.
1 parent 0d969c9 commit 50216b1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function process(File $phpcsFile, $stackPtr)
5656
{
5757
$tokens = $phpcsFile->getTokens();
5858

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

0 commit comments

Comments
 (0)