~ubuntu-branches/ubuntu/wily/php-codesniffer/wily

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.3/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/PropertyLabelSpacingSniff.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-21 14:42:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140721144241-g4orlcuk4jzn9mhs
Tags: 1.5.3-1
* Team upload
* Focus on stable release
* Update copyright
* Bump standards version to 3.9.5
* Update Homepage
* Use ${phppear:…} instead of hardcoding them
* Run tests in dh_auto_test
* Update patch with gbp pq
* Simplify configuration installation
* Edit package.xml to move script
* Add DEP-8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff.
 
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
 * Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff.
 
17
 *
 
18
 * Ensures that the colon in a property or label definition has a single
 
19
 * space after it and no space before it.
 
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: 1.5.3
 
27
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
28
 */
 
29
class Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff implements PHP_CodeSniffer_Sniff
 
30
{
 
31
 
 
32
    /**
 
33
     * A list of tokenizers this sniff supports.
 
34
     *
 
35
     * @var array
 
36
     */
 
37
    public $supportedTokenizers = array('JS');
 
38
 
 
39
 
 
40
    /**
 
41
     * Returns an array of tokens this test wants to listen for.
 
42
     *
 
43
     * @return array
 
44
     */
 
45
    public function register()
 
46
    {
 
47
        return array(
 
48
                T_PROPERTY,
 
49
                T_LABEL,
 
50
               );
 
51
 
 
52
    }//end register()
 
53
 
 
54
 
 
55
    /**
 
56
     * Processes this test, when one of its tokens is encountered.
 
57
     *
 
58
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
 
59
     * @param int                  $stackPtr  The position of the current token
 
60
     *                                        in the stack passed in $tokens.
 
61
     *
 
62
     * @return void
 
63
     */
 
64
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 
65
    {
 
66
        $tokens = $phpcsFile->getTokens();
 
67
 
 
68
        $colon = $phpcsFile->findNext(T_COLON, ($stackPtr + 1));
 
69
 
 
70
        if ($colon !== ($stackPtr + 1)) {
 
71
            $error = 'There must be no space before the colon in a property/label declaration';
 
72
            $phpcsFile->addError($error, $stackPtr, 'Before');
 
73
        }
 
74
 
 
75
        if ($tokens[($colon + 1)]['code'] !== T_WHITESPACE || $tokens[($colon + 1)]['content'] !== ' ') {
 
76
            $error = 'There must be a single space after the colon in a property/label declaration';
 
77
            $phpcsFile->addError($error, $stackPtr, 'After');
 
78
        }
 
79
 
 
80
    }//end process()
 
81
 
 
82
 
 
83
}//end class
 
84
 
 
85
?>