~ubuntu-branches/ubuntu/utopic/php-codesniffer/utopic-proposed

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.1.0/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2012-05-31 16:37:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120531163724-u6aiaubu8ks5dh5z
Tags: 1.3.4-0.1
* Non-maintainer upload.
* New upstream release (Closes: #599617, #634825).
* Swtiched debian/copyright to format 1.0 (rewrite was needed anyway, as the
upstream license changed).
* Switched package to pkg-php-tools and debhelper 8 sequencer.
* Now running unit tests at build time (so depends on phpunit (>= 3.6)).
* Section is now PHP.
* Added missing Build-Depends-Indep: php-pear.
* Added missing ${misc:Depends}.
* Added Vcs fields.
* Added homepage field.
* Reviewed short and long description.
* Added dependency on php-timer.
* Standards-Version: is now 3.9.3 (lots of changes, see above...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
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.1.0
29
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 
 */
31
 
class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff
32
 
{
33
 
 
34
 
    /**
35
 
     * The valid EOL character.
36
 
     *
37
 
     * @var string
38
 
     */
39
 
    protected $eolChar = "\n";
40
 
 
41
 
 
42
 
    /**
43
 
     * Returns an array of tokens this test wants to listen for.
44
 
     *
45
 
     * @return array
46
 
     */
47
 
    public function register()
48
 
    {
49
 
        return array(T_OPEN_TAG);
50
 
 
51
 
    }//end register()
52
 
 
53
 
 
54
 
    /**
55
 
     * Processes this sniff, when one of its tokens is encountered.
56
 
     *
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.
60
 
     *
61
 
     * @return void
62
 
     */
63
 
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
64
 
    {
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) {
68
 
                return;
69
 
            }
70
 
        }
71
 
 
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);
81
 
        }
82
 
 
83
 
    }//end process()
84
 
 
85
 
 
86
 
}//end class
87
 
 
88
 
?>