Completed
Pull Request — master (#526)
by Juliette
01:35
created

RemovedConstantsSniff::getItemArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * \PHPCompatibility\Sniffs\PHP\RemovedConstantsSniff.
4
 *
5
 * @category PHP
6
 * @package  PHPCompatibility
7
 * @author   Juliette Reinders Folmer <[email protected]>
8
 */
9
10
namespace PHPCompatibility\Sniffs\PHP;
11
12
use PHPCompatibility\AbstractRemovedFeatureSniff;
13
14
/**
15
 * \PHPCompatibility\Sniffs\PHP\RemovedConstantsSniff.
16
 *
17
 * @category PHP
18
 * @package  PHPCompatibility
19
 * @author   Juliette Reinders Folmer <[email protected]>
20
 */
21
class RemovedConstantsSniff extends AbstractRemovedFeatureSniff
22
{
23
24
    /**
25
     * A list of removed PHP Constants.
26
     *
27
     * The array lists : version number with false (deprecated) or true (removed).
28
     * If's sufficient to list the first version where the constant was deprecated/removed.
29
     *
30
     * Note: PHP Constants are case-sensitive!
31
     *
32
     * @var array(string => array(string => bool|string|null))
33
     */
34
    protected $removedConstants = array(
35
        'PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT' => array(
36
            '7.0' => true,
37
        ),
38
39
        'INTL_IDNA_VARIANT_2003' => array(
40
            '7.2' => false,
41
        ),
42
43
    );
44
45
46
    /**
47
     * Returns an array of tokens this test wants to listen for.
48
     *
49
     * @return array
50
     */
51
    public function register()
52
    {
53
        return array(T_STRING);
54
55
    }//end register()
56
57
58
    /**
59
     * Processes this test, when one of its tokens is encountered.
60
     *
61
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
62
     * @param int                   $stackPtr  The position of the current token in
63
     *                                         the stack passed in $tokens.
64
     *
65
     * @return void
66
     */
67 View Code Duplication
    public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
68
    {
69
        $tokens       = $phpcsFile->getTokens();
70
        $constantName = $tokens[$stackPtr]['content'];
71
72
        if (isset($this->removedConstants[$constantName]) === false) {
73
            return;
74
        }
75
76
        if ($this->isUseOfGlobalConstant($phpcsFile, $stackPtr) === false) {
77
            return;
78
        }
79
80
        $itemInfo = array(
81
            'name' => $constantName,
82
        );
83
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
84
85
    }//end process()
86
87
88
    /**
89
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
90
     *
91
     * @param array $itemInfo Base information about the item.
92
     *
93
     * @return array Version and other information about the item.
94
     */
95
    public function getItemArray(array $itemInfo)
96
    {
97
        return $this->removedConstants[$itemInfo['name']];
98
    }
99
100
101
    /**
102
     * Get the error message template for this sniff.
103
     *
104
     * @return string
105
     */
106
    protected function getErrorMsgTemplate()
107
    {
108
        return 'The constant "%s" is ';
109
    }
110
111
}//end class
112