1<?php
2/**
3 * Generic_Sniffs_Files_InlineHTMLSniff.
4 *
5 * PHP version 5
6 *
7 * @category  PHP
8 * @package   PHP_CodeSniffer
9 * @author    Greg Sherwood <gsherwood@squiz.net>
10 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12 * @link      http://pear.php.net/package/PHP_CodeSniffer
13 */
14
15/**
16 * Generic_Sniffs_Files_InlineHTMLSniff.
17 *
18 * Ensures the whole file is PHP only, with no whitespace or inline HTML anywhere
19 * in the file.
20 *
21 * @category  PHP
22 * @package   PHP_CodeSniffer
23 * @author    Greg Sherwood <gsherwood@squiz.net>
24 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
25 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
26 * @version   Release: @package_version@
27 * @link      http://pear.php.net/package/PHP_CodeSniffer
28 */
29class Generic_Sniffs_Files_InlineHTMLSniff implements PHP_CodeSniffer_Sniff
30{
31
32
33    /**
34     * Returns an array of tokens this test wants to listen for.
35     *
36     * @return array
37     */
38    public function register()
39    {
40        return array(T_INLINE_HTML);
41
42    }//end register()
43
44
45    /**
46     * Processes this test, when one of its tokens is encountered.
47     *
48     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
49     * @param int                  $stackPtr  The position of the current token in
50     *                                        the stack passed in $tokens.
51     *
52     * @return void
53     */
54    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55    {
56        // Ignore shebang lines.
57        $tokens = $phpcsFile->getTokens();
58        if (substr($tokens[$stackPtr]['content'], 0, 2) === '#!') {
59            return;
60        }
61
62        $error = 'PHP files must only contain PHP code';
63        $phpcsFile->addError($error, $stackPtr, 'Found');
64
65        return $phpcsFile->numTokens;
66
67    }//end process()
68
69
70}//end class
71