Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FunctionWatchdogSniff.php

function 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

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php, line 50

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');
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal