3
* Generic_Sniffs_Files_LineEndingsSniff.
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
13
* @version CVS: $Id: LineEndingsSniff.php,v 1.2 2007/07/23 01:47:52 squiz Exp $
14
* @link http://pear.php.net/package/PHP_CodeSniffer
18
* Generic_Sniffs_Files_LineEndingsSniff.
20
* Checks that end of line characters are correct.
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.1.0
29
* @link http://pear.php.net/package/PHP_CodeSniffer
31
class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff
35
* The valid EOL character.
39
protected $eolChar = "\n";
43
* Returns an array of tokens this test wants to listen for.
47
public function register()
49
return array(T_OPEN_TAG);
55
* Processes this sniff, when one of its tokens is encountered.
57
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
58
* @param int $stackPtr The position of the current token in the
59
* stack passed in $tokens.
63
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
65
// We are only interested if this is the first open tag.
66
if ($stackPtr !== 0) {
67
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
72
if ($phpcsFile->eolChar !== $this->eolChar) {
73
$expected = $this->eolChar;
74
$expected = str_replace("\n", '\n', $expected);
75
$expected = str_replace("\r", '\r', $expected);
76
$found = $phpcsFile->eolChar;
77
$found = str_replace("\n", '\n', $found);
78
$found = str_replace("\r", '\r', $found);
79
$error = "End of line character is invalid; expected \"$expected\" but found \"$found\"";
80
$phpcsFile->addError($error, $stackPtr);