Completed
Push — master ( a32632...c637b7 )
by Juliette
9s
created

RemovedGlobalVariablesSniff::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff.
4
 *
5
 * @category  PHP
6
 * @package   PHPCompatibility
7
 * @author    Wim Godden <[email protected]>
8
 */
9
10
/**
11
 * PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff.
12
 *
13
 * Discourages the use of removed global variables. Suggests alternative extensions if available
14
 *
15
 * @category  PHP
16
 * @package   PHPCompatibility
17
 * @author    Wim Godden <[email protected]>
18
 */
19
class PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff extends PHPCompatibility_AbstractRemovedFeatureSniff
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...
20
{
21
22
    /**
23
     * A list of removed global variables with their alternative, if any.
24
     *
25
     * The array lists : version number with false (deprecated) and true (removed).
26
     * If's sufficient to list the first version where the variable was deprecated/removed.
27
     *
28
     * @var array(string|null)
29
     */
30
    protected $removedGlobalVariables = array(
31
        'HTTP_RAW_POST_DATA' => array(
32
            '5.6' => false,
33
            '7.0' => true,
34
            'alternative' => 'php://input'
35
        ),
36
    );
37
38
    /**
39
     * Returns an array of tokens this test wants to listen for.
40
     *
41
     * @return array
42
     */
43
    public function register()
44
    {
45
        return array(T_VARIABLE);
46
47
    }//end register()
48
49
    /**
50
     * Processes this test, when one of its tokens is encountered.
51
     *
52
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
     * @param int                  $stackPtr  The position of the current token in the
54
     *                                        stack passed in $tokens.
55
     *
56
     * @return void
57
     */
58 View Code Duplication
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $tokens  = $phpcsFile->getTokens();
61
        $varName = substr($tokens[$stackPtr]['content'], 1);
62
63
        if (isset($this->removedGlobalVariables[$varName]) === false) {
64
            return;
65
        }
66
67
        $itemInfo = array(
68
            'name' => $varName,
69
        );
70
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
71
72
    }//end process()
73
74
75
    /**
76
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
77
     *
78
     * @param array $itemInfo Base information about the item.
79
     *
80
     * @return array Version and other information about the item.
81
     */
82
    public function getItemArray(array $itemInfo)
83
    {
84
        return $this->removedGlobalVariables[$itemInfo['name']];
85
    }
86
87
88
    /**
89
     * Get the error message template for this sniff.
90
     *
91
     * @return string
92
     */
93
    protected function getErrorMsgTemplate()
94
    {
95
        return "Global variable '\$%s' is ";
96
    }
97
98
99
}//end class
100