Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SpacesAroundConcatSniff.php « Files « Sniffs « PMAStandard - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d6e276bedf9c6282f849788f2574325351cd1c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Class for a sniff to oblige whitespaces before and after a concatenation operator
 *
 * This Sniff check if a whitespace is missing before or after any concatenation
 * operator.
 * The concatenation operator is identified by the PHP token T_STRING_CONCAT
 * The whitespace is identified by the PHP token T_WHITESPACE
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @author   Nicolas Giraud <g.nicolas_89@hotmail.fr>
 * @since    September, the 12th 2013
 */

/// {{{ PMAStandard_Sniffs_Files_SpacesAroundConcatSniff
/**
 * Sniff to oblige whitespaces before and after a concatenation operator
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @name     SpacesAroundConcatSniff
 * @author   Nicolas Giraud <g.nicolas_89@hotmail.fr>
 * @version  Release: 1.0
 */
class PMAStandard_Sniffs_Files_SpacesAroundConcatSniff implements PHP_CodeSniffer_Sniff
{

    // {{{ register()

    /**
     * Returns the token types that this sniff is interested in.
     *
     * @name register
     * @access public
     * @see PHP_CodeSniffer_Sniff::register()
     *
     * @return array(int)
     */
    public function register()
    {
        return array(T_STRING_CONCAT);

    }//end register()

    // }}}
    // {{{ process()

    /**
     * Processes the tokens that this sniff is interested in.
     *
     * @name process
     * @access public
     * @see PHP_CodeSniffer_Sniff::process()
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
     * @param int                  $stackPtr  The position in the stack where the token was found.
     *
     * @return void
     */
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        if ($tokens[$stackPtr-1]['type'] !== 'T_WHITESPACE') {
            $warning = 'Whitespace is expected before any concat operator "."';
            $phpcsFile->addWarning($warning, $stackPtr, 'Found');
        }
        if ($tokens[$stackPtr+1]['type'] !== 'T_WHITESPACE') {
            $warning = 'Whitespace is expected after any concat operator "."';
            $phpcsFile->addWarning($warning, $stackPtr, 'Found');
        }
    }//end process()

    // }}}

}//end class

// }}}

?>