ThemeSniff.php in Coder 8.2
File
coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php
View source
<?php
namespace DrupalPractice\Sniffs\FunctionCalls;
use PHP_CodeSniffer\Files\File;
use Drupal\Sniffs\Semantics\FunctionCall;
class ThemeSniff extends FunctionCall {
protected $reservedFunctions = array(
'theme_get_registry',
'theme_get_setting',
'theme_render_template',
'theme_enable',
'theme_disable',
'theme_get_suggestions',
);
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,
));
}
}
Classes
Name |
Description |
ThemeSniff |
\DrupalPractice\Sniffs\FunctionCalls\Checks that theme functions are not directly called. |