Completed
Push — master ( b1425f...4cb819 )
by Wim
02:29
created

process()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 8.7624
cc 6
eloc 11
nc 3
nop 2
1
<?php
2
3
class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
4
{
5
    /** @var array */
6
    protected $supportByVersion = array(
7
        '5.3' => false,
8
        '5.4' => true
9
    );
10
11
    /** @var array */
12
    protected $errorByForbiddenTokens = array(
13
        'T_OPEN_SHORT_ARRAY' => 'Short array syntax (open)',
14
        'T_CLOSE_SHORT_ARRAY' => 'Short array syntax (close)'
15
    );
16
17
    /**
18
     * Returns an array of tokens this test wants to listen for.
19
     *
20
     * @return array
21
     */
22
    public function register()
23
    {
24
        return array(T_OPEN_TAG);
25
    }//end register()
26
27
28
    /**
29
     * Processes this test, when one of its tokens is encountered.
30
     *
31
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
32
     * @param int                  $stackPtr  The position of the current token in
33
     *                                        the stack passed in $tokens.
34
     *
35
     * @return void
36
     */
37
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
38
    {
39
        $tokens = $phpcsFile->getTokens();
40
41
        foreach ($tokens as $currentToken) {
42
            if (!isset($this->errorByForbiddenTokens[$currentToken['type']])) {
43
                continue;
44
            }
45
46
            foreach ($this->supportByVersion as $version => $support) {
47
                if ($this->supportsBelow($version)) {
48
                    if ($support) {
49
                        continue;
50
                    }
51
52
                    $error = $this->errorByForbiddenTokens[$currentToken['type']] . ' is available since 5.4';
53
                    $phpcsFile->addError($error, $stackPtr);
54
                }
55
            }
56
        }
57
    }//end process()
58
59
}//end class