Skip to content

Commit 358362c

Browse files
committed
Generic/UnnecessaryFinalModifier: make the sniff more efficient
No need to token walk the contents of functions as the `final` keyword cannot be used in them anyway.
1 parent 9eee9f5 commit 358362c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function process(File $phpcsFile, $stackPtr)
7373
$error = 'Unnecessary FINAL modifier in FINAL class';
7474
$phpcsFile->addWarning($error, $next, 'Found');
7575
}
76+
77+
// Skip over the contents of functions as those can't contain the `final` keyword anyway.
78+
if ($tokens[$next]['code'] === T_FUNCTION
79+
&& isset($tokens[$next]['scope_closer']) === true
80+
) {
81+
$next = $tokens[$next]['scope_closer'];
82+
}
7683
}
7784

7885
}//end process()

0 commit comments

Comments
 (0)