Subversion Repositories Applications.framework

Rev

Rev 5 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 aurelien 1
<?php
2
/**
3
 * Generic_Sniffs_Files_LineEndingsSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @author    Marc McIntyre <mmcintyre@squiz.net>
11
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
12
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
34 aurelien 13
 * @version   CVS: $Id: LineEndingsSniff.php 34 2009-04-09 07:34:39Z aurelien $
5 aurelien 14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
/**
18
 * Generic_Sniffs_Files_LineEndingsSniff.
19
 *
20
 * Checks that end of line characters are correct.
21
 *
22
 * @category  PHP
23
 * @package   PHP_CodeSniffer
24
 * @author    Greg Sherwood <gsherwood@squiz.net>
25
 * @author    Marc McIntyre <mmcintyre@squiz.net>
26
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
27
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
28
 * @version   Release: 1.2.0RC1
29
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 */
31
class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff
32
{
33
 
34
    /**
35
     * A list of tokenizers this sniff supports.
36
     *
37
     * @var array
38
     */
39
    public $supportedTokenizers = array(
40
                                   'PHP',
41
                                   'JS',
42
                                   'CSS',
43
                                  );
44
 
45
    /**
46
     * The valid EOL character.
47
     *
48
     * @var string
49
     */
50
    protected $eolChar = "\n";
51
 
52
 
53
    /**
54
     * Returns an array of tokens this test wants to listen for.
55
     *
56
     * @return array
57
     */
58
    public function register()
59
    {
60
        return array(T_OPEN_TAG);
61
 
62
    }//end register()
63
 
64
 
65
    /**
66
     * Processes this sniff, when one of its tokens is encountered.
67
     *
68
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
69
     * @param int                  $stackPtr  The position of the current token in the
70
     *                                        stack passed in $tokens.
71
     *
72
     * @return void
73
     */
74
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
75
    {
76
        // We are only interested if this is the first open tag.
77
        if ($stackPtr !== 0) {
78
            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
79
                return;
80
            }
81
        }
82
 
83
        if ($phpcsFile->eolChar !== $this->eolChar) {
84
            $expected = $this->eolChar;
85
            $expected = str_replace("\n", '\n', $expected);
86
            $expected = str_replace("\r", '\r', $expected);
87
            $found    = $phpcsFile->eolChar;
88
            $found    = str_replace("\n", '\n', $found);
89
            $found    = str_replace("\r", '\r', $found);
90
            $error    = "End of line character is invalid; expected \"$expected\" but found \"$found\"";
91
            $phpcsFile->addError($error, $stackPtr);
92
        }
93
 
94
    }//end process()
95
 
96
 
97
}//end class
98
 
99
?>