You are here

public function ThemeSniff::process in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php \DrupalPractice\Sniffs\FunctionCalls\ThemeSniff::process()
  2. 8.3.x coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php \DrupalPractice\Sniffs\FunctionCalls\ThemeSniff::process()

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.

Return value

void

Overrides FunctionCall::process

File

coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php, line 49

Class

ThemeSniff
\DrupalPractice\Sniffs\FunctionCalls\Checks that theme functions are not directly called.

Namespace

DrupalPractice\Sniffs\FunctionCalls

Code

public function process(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  $functionName = $tokens[$stackPtr]['content'];
  if (strpos($functionName, 'theme_') !== 0 || in_array($functionName, $this->reservedFunctions) === true || $this
    ->isFunctionCall($phpcsFile, $stackPtr) === false) {
    return;
  }
  $themeName = substr($functionName, 6);
  $warning = "Do not call theme functions directly, use theme('%s', ...) instead";
  $phpcsFile
    ->addWarning($warning, $stackPtr, 'ThemeFunctionDirect', array(
    $themeName,
  ));
}