Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
$reportPtr = null;
$openParens = 0;

$message = 'Cache expiry time could not be determined. Please inspect that the fourth parameter passed to %s() evaluates to 300 seconds or more. Found: "%s"';
$error_code = 'CacheTimeUndetermined';
$data = [ $matched_content, $parameters[4]['raw'] ];

for ( $i = $param['start']; $i <= $param['end']; $i++ ) {
if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) === true ) {
$tokensAsString .= ' ';
Expand Down Expand Up @@ -151,9 +155,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
}

// Encountered an unexpected token. Manual inspection needed.
$message = 'Cache expiry time could not be determined. Please inspect that the fourth parameter passed to %s() evaluates to 300 seconds or more. Found: "%s"';
$data = [ $matched_content, $parameters[4]['raw'] ];
$this->phpcsFile->addWarning( $message, $reportPtr, 'CacheTimeUndetermined', $data );
$this->phpcsFile->addWarning( $message, $reportPtr, $error_code, $data );

return;
}
Expand All @@ -177,7 +179,17 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
}
}

$time = eval( "return $tokensAsString;" ); // phpcs:ignore Squiz.PHP.Eval -- No harm here.
$time = @eval( "return $tokensAsString;" ); // phpcs:ignore Squiz.PHP.Eval,WordPress.PHP.NoSilencedErrors -- No harm here.

if ( $time === false ) {
/*
* The eval resulted in a parse error. This will only happen for backfilled
* arithmetic operator tokens, like T_POW, on PHP versions in which the token
* did not exist. In that case, flag for manual inspection.
*/
$this->phpcsFile->addWarning( $message, $reportPtr, $error_code, $data );
return;
}

if ( $time < 300 && (int) $time !== 0 ) {
$message = 'Low cache expiry time of %s seconds detected. It is recommended to have 300 seconds or more.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function getWarningList() {
77 => 1,
78 => 1,
79 => 1,
82 => ( PHP_VERSION_ID > 50600 ) ? 0 : 1,
88 => 1,
94 => 1,
95 => 1,
Expand Down