TInHookSchemaSniff.php in Coder 8.2
File
coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php
View source
<?php
namespace Drupal\Sniffs\Semantics;
use Drupal\Sniffs\Semantics\FunctionDefinition;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
class TInHookSchemaSniff extends FunctionDefinition {
public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) {
$fileExtension = strtolower(substr($phpcsFile
->getFilename(), -7));
if ($fileExtension !== 'install') {
return;
}
$fileName = substr(basename($phpcsFile
->getFilename()), 0, -8);
$tokens = $phpcsFile
->getTokens();
if ($tokens[$stackPtr]['content'] !== $fileName . '_schema') {
return;
}
$string = $phpcsFile
->findNext(T_STRING, $tokens[$functionPtr]['scope_opener'], $tokens[$functionPtr]['scope_closer']);
while ($string !== false) {
if ($tokens[$string]['content'] === 't') {
$opener = $phpcsFile
->findNext(Tokens::$emptyTokens, $string + 1, null, true);
if ($opener !== false && $tokens[$opener]['code'] === T_OPEN_PARENTHESIS) {
$error = 'Do not use t() in hook_schema(), this will only generate overhead for translators';
$phpcsFile
->addError($error, $string, 'TFound');
}
}
$string = $phpcsFile
->findNext(T_STRING, $string + 1, $tokens[$functionPtr]['scope_closer']);
}
}
}