3
* Generic_Sniffs_PHP_DisallowShortOpenTagSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @author Marc McIntyre <mmcintyre@squiz.net>
11
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
13
* @link http://pear.php.net/package/PHP_CodeSniffer
17
* Generic_Sniffs_PHP_DisallowShortOpenTagSniff.
19
* Makes sure that shorthand PHP open tags are not used.
22
* @package PHP_CodeSniffer
23
* @author Greg Sherwood <gsherwood@squiz.net>
24
* @author Marc McIntyre <mmcintyre@squiz.net>
25
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
26
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
27
* @version Release: 1.3.4
28
* @link http://pear.php.net/package/PHP_CodeSniffer
30
class Generic_Sniffs_PHP_DisallowShortOpenTagSniff implements PHP_CodeSniffer_Sniff
35
* Returns an array of tokens this test wants to listen for.
39
public function register()
50
* Processes this test, when one of its tokens is encountered.
52
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
* @param int $stackPtr The position of the current token
54
* in the stack passed in $tokens.
58
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
60
$tokens = $phpcsFile->getTokens();
61
$openTag = $tokens[$stackPtr];
63
if ($openTag['content'] === '<?') {
64
$error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
65
$data = array($openTag['content']);
66
$phpcsFile->addError($error, $stackPtr, 'Found', $data);
69
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
70
$nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
71
$error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
77
$phpcsFile->addError($error, $stackPtr, 'EchoFound', $data);