* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Generic_Sniffs_Files_InlineHTMLSniff.
*
* Ensures the whole file is PHP only, with no whitespace or inline HTML anywhere
* in the file.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Files_InlineHTMLSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OPEN_TAG);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// Make sure this is the first open tag.
$previousOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
if ($previousOpenTag !== false) {
return;
}
$inline = $phpcsFile->findNext(T_INLINE_HTML, 0);
if ($inline === false) {
return;
}
$error = 'PHP files must only contain PHP code';
$phpcsFile->addError($error, $inline, 'Found');
}//end process()
}//end class