1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ParameterShadowSuperGlobalsSniffTest |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* ParameterShadowSuperGlobalsSniffTest |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ParameterShadowSuperGlobalsSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
const TEST_FILE = 'sniff-examples/parameter_shadow_superglobals.php'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* testParameterShadowSuperGlobals |
23
|
|
|
* |
24
|
|
|
* @group parameterShadowSuperGlobals |
25
|
|
|
* |
26
|
|
|
* @dataProvider dataParameterShadowSuperGlobals |
27
|
|
|
* |
28
|
|
|
* @param string $superglobal Parameter name. |
29
|
|
|
* @param int $line Line number where the error should occur. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function testParameterShadowSuperGlobal($superglobal, $line) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.3'); |
37
|
|
|
$this->assertNoViolation($file, $line); |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.4'); |
41
|
|
|
$this->assertError($file, $line, "Parameter shadowing super global ({$superglobal}) causes fatal error since PHP 5.4"); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* dataParameterShadowSuperGlobals |
46
|
|
|
* |
47
|
|
|
* @see testParameterShadowSuperGlobals() |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public function dataParameterShadowSuperGlobals() { |
52
|
|
|
return array( |
53
|
|
|
array('$GLOBALS', 4), |
54
|
|
|
array('$_SERVER', 5), |
55
|
|
|
array('$_GET', 6), |
56
|
|
|
array('$_POST', 7), |
57
|
|
|
array('$_FILES', 8), |
58
|
|
|
array('$_COOKIE', 9), |
59
|
|
|
array('$_SESSION', 10), |
60
|
|
|
array('$_REQUEST', 11), |
61
|
|
|
array('$_ENV', 12), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* testValidParameter |
68
|
|
|
* |
69
|
|
|
* @group parameterShadowSuperGlobals |
70
|
|
|
* |
71
|
|
|
* @dataProvider dataValidParameter |
72
|
|
|
* |
73
|
|
|
* @param int $line The line number. |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function testValidParameter($line) |
78
|
|
|
{ |
79
|
|
|
$file = $this->sniffFile(self::TEST_FILE); |
80
|
|
|
$this->assertNoViolation($file, $line); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Data provider. |
85
|
|
|
* |
86
|
|
|
* @see testValidParameter() |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function dataValidParameter() |
91
|
|
|
{ |
92
|
|
|
return array( |
93
|
|
|
array(15), |
94
|
|
|
array(16), |
95
|
|
|
array(17), |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.