public function Drupal_Sniffs_ControlStructures_TemplateControlStructureSniff::process in Coder 7.2
Processes this test, when one of its tokens is encountered.
Parameters
PHP_CodeSniffer_File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
void
File
- coder_sniffer/
Drupal/ Sniffs/ ControlStructures/ TemplateControlStructureSniff.php, line 53
Class
- Drupal_Sniffs_ControlStructures_TemplateControlStructureSniff
- Checks that control structures in template files use the alternative syntax with ":" and end statements.
Code
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
// Only process this sniff for template files.
$fileExtension = strtolower(substr($phpcsFile
->getFilename(), -8));
if ($fileExtension !== '.tpl.php') {
return;
}
$tokens = $phpcsFile
->getTokens();
// If there is a scope opener, then there is a opening curly brace.
if (isset($tokens[$stackPtr]['scope_opener']) === true && $tokens[$tokens[$stackPtr]['scope_opener']]['code'] !== T_COLON) {
$error = 'The control statement should use the ":" alternative syntax instead of curly braces in template files';
$phpcsFile
->addError($error, $stackPtr, 'CurlyBracket');
}
}