Skip to content

Commit

Permalink
BadFunctions/EasyRFI: minor code simplification [1]
Browse files Browse the repository at this point in the history
Putting the `findNext()` in the `while` condition allows to simplify the `if` conditions within the loop.
  • Loading branch information
jrfnl committed Mar 16, 2020
1 parent 98cca8b commit cc89cb4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Security/Sniffs/BadFunctions/EasyRFISniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$s = $stackPtr;

while ($s) {
$s = $phpcsFile->findNext($this->search, $s + 1, $closer, true);

while (($s = $phpcsFile->findNext($this->search, $s + 1, $closer, true)) !== false) {
$data = array(
$tokens[$s]['content'],
$tokens[$stackPtr]['content'],
);

if ($s && $utils::is_token_user_input($tokens[$s])) {
if ($utils::is_token_user_input($tokens[$s])) {
if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') || !$utils::is_token_false_positive($tokens[$s], $tokens[$s+2])) {
$phpcsFile->addError('Easy RFI detected because of direct user input with %s on %s', $s, 'ErrEasyRFI', $data);
}
} elseif ($s && \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') && $tokens[$s]['content'] != '.') {
} elseif (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') && $tokens[$s]['content'] != '.') {
$phpcsFile->addWarning('Possible RFI detected with %s on %s', $s, 'WarnEasyRFI', $data);
}
}
Expand Down

0 comments on commit cc89cb4

Please sign in to comment.