You are here

public function FunctionWatchdogSniff::processFunctionCall in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php \Drupal\Sniffs\Semantics\FunctionWatchdogSniff::processFunctionCall()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php \Drupal\Sniffs\Semantics\FunctionWatchdogSniff::processFunctionCall()

Processes this function call.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the function call in: the stack.

int $openBracket The position of the opening: parenthesis in the stack.

int $closeBracket The position of the closing: parenthesis in the stack.

Return value

void

File

coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php, line 51

Class

FunctionWatchdogSniff
Checks that the second argument to watchdog() is not enclosed with t().

Namespace

Drupal\Sniffs\Semantics

Code

public function processFunctionCall(File $phpcsFile, $stackPtr, $openBracket, $closeBracket) {
  $tokens = $phpcsFile
    ->getTokens();

  // Get the second argument passed to watchdog().
  $argument = $this
    ->getArgument(2);
  if ($argument === false) {
    $error = 'The second argument to watchdog() is missing';
    $phpcsFile
      ->addError($error, $stackPtr, 'WatchdogArgument');
    return;
  }
  if ($tokens[$argument['start']]['code'] === T_STRING && $tokens[$argument['start']]['content'] === 't') {
    $error = 'The second argument to watchdog() should not be enclosed with t()';
    $phpcsFile
      ->addError($error, $argument['start'], 'WatchdogT');
  }
  $concatFound = $phpcsFile
    ->findNext(T_STRING_CONCAT, $argument['start'], $argument['end']);
  if ($concatFound !== false) {
    $error = 'Concatenating translatable strings is not allowed, use placeholders instead and only one string literal';
    $phpcsFile
      ->addError($error, $concatFound, 'Concat');
  }
}