Skip to content

Commit

Permalink
Generic/UnnecessaryFinalModifier: make the sniff more efficient
Browse files Browse the repository at this point in the history
No need to token walk the contents of functions as the `final` keyword cannot be used in them anyway.
  • Loading branch information
jrfnl committed May 18, 2023
1 parent 9eee9f5 commit 358362c
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public function process(File $phpcsFile, $stackPtr)
$error = 'Unnecessary FINAL modifier in FINAL class';
$phpcsFile->addWarning($error, $next, 'Found');
}

// Skip over the contents of functions as those can't contain the `final` keyword anyway.
if ($tokens[$next]['code'] === T_FUNCTION
&& isset($tokens[$next]['scope_closer']) === true
) {
$next = $tokens[$next]['scope_closer'];
}
}

}//end process()
Expand Down

0 comments on commit 358362c

Please sign in to comment.