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 int $line Line number where the error should occur. |
29
|
|
|
* @param string $octal (Start of) Binary number as a string. |
|
|
|
|
30
|
|
|
* @param bool $testNoViolation Whether or not to test for noViolation. |
|
|
|
|
31
|
|
|
* Defaults to true. Set to false if another error is |
32
|
|
|
* expected on the same line (invalid binary) |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function testParameterShadowSuperGlobal($superglobal, $line) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.3'); |
40
|
|
|
$this->assertNoViolation($file, $line); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.4'); |
44
|
|
|
$this->assertError($file, $line, "Parameter shadowing super global ({$superglobal}) causes fatal error since PHP 5.4"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* dataParameterShadowSuperGlobals |
49
|
|
|
* |
50
|
|
|
* @see testParameterShadowSuperGlobals() |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function dataParameterShadowSuperGlobals() { |
55
|
|
|
return array( |
56
|
|
|
array('$GLOBALS', 4), |
57
|
|
|
array('$_SERVER', 5), |
58
|
|
|
array('$_GET', 6), |
59
|
|
|
array('$_POST', 7), |
60
|
|
|
array('$_FILES', 8), |
61
|
|
|
array('$_COOKIE', 9), |
62
|
|
|
array('$_SESSION', 10), |
63
|
|
|
array('$_REQUEST', 11), |
64
|
|
|
array('$_ENV', 12), |
65
|
|
|
array('$globals', 15), |
66
|
|
|
array('$_post', 16), |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* testValidParameter |
73
|
|
|
* |
74
|
|
|
* @group parameterShadowSuperGlobals |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testValidParameter() { |
79
|
|
|
$file = $this->sniffFile(self::TEST_FILE); |
80
|
|
|
$this->assertNoViolation($file , 19); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
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.