Failed Conditions
Branch test-scrutinizer-coverage (7e25b2)
by Wim
13:51 queued 10:07
created

ConstantArraysUsingConstSniff::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 12
cts 13
cp 0.9231
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 2
crap 3.004
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_ConstantArraysUsingConstSniff.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @category PHP
8
 * @package  PHPCompatibility
9
 * @author   Juliette Reinders Folmer <[email protected]>
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_ConstantArraysUsingConstSniff.
14
 *
15
 * Constant arrays using the constant keyword in PHP 5.6
16
 *
17
 * PHP version 5.6
18
 *
19
 * @category PHP
20
 * @package  PHPCompatibility
21
 * @author   Juliette Reinders Folmer <[email protected]>
22
 */
23
class PHPCompatibility_Sniffs_PHP_ConstantArraysUsingConstSniff 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...
24
{
25
26
    /**
27
     * Returns an array of tokens this test wants to listen for.
28
     *
29
     * @return array
30
     */
31 9
    public function register()
32
    {
33 9
        return array(T_CONST);
34
    }
35
36
    /**
37
     * Processes this test, when one of its tokens is encountered.
38
     *
39
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
40
     * @param int                  $stackPtr  The position of the current token in the
41
     *                                        stack passed in $tokens.
42
     *
43
     * @return void
44
     */
45 2
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
    {
47 2
        if ($this->supportsBelow('5.5') !== true) {
48 1
            return;
49
        }
50
51
        $find = array(
52 1
            T_ARRAY             => T_ARRAY,
53 1
            T_OPEN_SHORT_ARRAY  => T_OPEN_SHORT_ARRAY,
54 1
            T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY,
55
        );
56
57 1
        $hasArray = $phpcsFile->findNext($find, ($stackPtr + 1), null, false, null, true);
58 1
        if ($hasArray !== false) {
59 1
            $phpcsFile->addError(
60 1
                'Constant arrays using the "const" keyword are not allowed in PHP 5.5 or earlier',
61
                $hasArray,
62 1
                'Found'
63
            );
64
        }
65 1
    }
66
}
67