Completed
Pull Request — master (#238)
by Juliette
02:18
created

process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 2
1
<?php
2
3
class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    /**
7
     * Returns an array of tokens this test wants to listen for.
8
     *
9
     * @return array
10
     */
11
    public function register()
12
    {
13
        return array(
14
            T_OPEN_SHORT_ARRAY,
15
            T_CLOSE_SHORT_ARRAY,
16
        );
17
    }//end register()
18
19
20
    /**
21
     * Processes this test, when one of its tokens is encountered.
22
     *
23
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
24
     * @param int                  $stackPtr  The position of the current token in
25
     *                                        the stack passed in $tokens.
26
     *
27
     * @return void
28
     */
29
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
30
    {
31
        if ($this->supportsBelow('5.3') === false) {
32
            return;
33
        }
34
35
        $tokens = $phpcsFile->getTokens();
36
        $token  = $tokens[$stackPtr];
37
38
        $error = '%s is available since 5.4';
39
        $data  = array();
40
41
        if ($token['type'] === 'T_OPEN_SHORT_ARRAY' ) {
42
            $data[] = 'Short array syntax (open)';
43
        } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY' ) {
44
            $data[] = 'Short array syntax (close)';
45
        }
46
47
        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
48
49
    }//end process()
50
51
}//end class
52