Completed
Pull Request — master (#163)
by Juliette
06:47 queued 04:15
created

RemovedFunctionParameterSniffTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 132
Duplicated Lines 12.88 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 12
c 6
b 2
f 2
lcom 1
cbo 1
dl 17
loc 132
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testRemovedParameter() 17 17 4
A dataRemovedParameter() 0 7 1
A testDeprecatedRemovedParameter() 0 17 4
A dataDeprecatedRemovedParameter() 0 7 1
A testValidParameter() 0 5 1
A dataValidParameter() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Removed Functions Parameter Sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Removed Functions Parameter Sniff test file
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class RemovedFunctionParameterSniffTest 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/removed_function_parameter.php';
20
21
    /**
22
     * testRemovedParameter
23
     *
24
     * @dataProvider dataRemovedParameter
25
     *
26
     * @param string $functionName  Function name.
27
     * @param string $parameterName Parameter name.
28
     * @param string $removedIn     The PHP version in which the parameter was removed.
29
     * @param array  $lines         The line numbers in the test file which apply to this class.
30
     * @param string $okVersion     A PHP version in which the parameter was ok to be used.
31
     * @param string $testVersion   Optional. A PHP version in which to test for the removal message.
32
     *
33
     * @return void
34
     */
35 View Code Duplication
    public function testRemovedParameter($functionName, $parameterName, $removedIn, $lines, $okVersion, $testVersion = null)
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...
36
    {
37
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
38
        foreach ($lines as $line) {
39
            $this->assertNoViolation($file, $line);
40
        }
41
42
        if (isset($testVersion)){
43
            $file = $this->sniffFile(self::TEST_FILE, $testVersion);
44
        }
45
        else {
46
            $file = $this->sniffFile(self::TEST_FILE, $removedIn);
47
        }
48
        foreach ($lines as $line) {
49
            $this->assertError($file, $line, "The \"{$parameterName}\" parameter for function {$functionName} was removed in PHP version {$removedIn}");
50
        }
51
    }
52
53
    /**
54
     * Data provider.
55
     *
56
     * @see testRemovedParameter()
57
     *
58
     * @return array
59
     */
60
    public function dataRemovedParameter()
61
    {
62
        return array(
63
            array('ldap_first_attribute', 'ber_identifier', '5.2.4', array(11), '5.2', '5.3'),
64
            array('ldap_next_attribute', 'ber_identifier', '5.2.4', array(12), '5.2', '5.3'),
65
        );
66
    }
67
68
69
    /**
70
     * testDeprecatedRemovedParameter
71
     *
72
     * @dataProvider dataDeprecatedRemovedParameter
73
     *
74
     * @param string $functionName  Function name.
75
     * @param string $parameterName Parameter name.
76
     * @param string $deprecatedIn  The PHP version in which the parameter was deprecated.
77
     * @param string $removedIn     The PHP version in which the parameter was removed.
78
     * @param array  $lines         The line numbers in the test file which apply to this class.
79
     * @param string $okVersion     A PHP version in which the parameter was ok to be used.
80
     *
81
     * @return void
82
     */
83
    public function testDeprecatedRemovedParameter($functionName, $parameterName, $deprecatedIn, $removedIn, $lines, $okVersion)
84
    {
85
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
86
        foreach ($lines as $line) {
87
            $this->assertNoViolation($file, $line);
88
        }
89
90
        $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
91
        foreach ($lines as $line) {
92
            $this->assertWarning($file, $line, "The \"{$parameterName}\" parameter for function {$functionName} was deprecated in PHP version {$deprecatedIn}");
93
        }
94
95
        $file = $this->sniffFile(self::TEST_FILE, $removedIn);
96
        foreach ($lines as $line) {
97
            $this->assertError($file, $line, "The \"{$parameterName}\" parameter for function {$functionName} was deprecated in PHP version {$deprecatedIn} and removed in PHP version {$removedIn}");
98
        }
99
    }
100
101
    /**
102
     * Data provider.
103
     *
104
     * @see testDeprecatedRemovedParameter()
105
     *
106
     * @return array
107
     */
108
    public function dataDeprecatedRemovedParameter()
109
    {
110
        return array(
111
            array('mktime', 'is_dst', '5.1', '7.0', array(8), '5.0'),
112
            array('gmmktime', 'is_dst', '5.1', '7.0', array(9), '5.0'),
113
        );
114
    }
115
116
117
    /**
118
     * testValidParameter
119
     *
120
     * @dataProvider dataValidParameter
121
     *
122
     * @param int $line The line number.
123
     *
124
     * @return void
125
     */
126
    public function testValidParameter($line)
127
    {
128
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
129
        $this->assertNoViolation($file, $line);
130
    }
131
132
    /**
133
     * Data provider.
134
     *
135
     * @see testValidParameter()
136
     *
137
     * @return array
138
     */
139
    public function dataValidParameter()
140
    {
141
        return array(
142
            array(4),
143
            array(5),
144
        );
145
    }
146
147
}
148