Completed
Pull Request — master (#218)
by Juliette
03:23
created

dataValidParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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
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...
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)
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...
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