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 |
||
16 | class DeprecatedIniDirectivesSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/deprecated_ini_directives.php'; |
||
20 | |||
21 | /** |
||
22 | * Test valid directive |
||
23 | * |
||
24 | * @return void |
||
25 | */ |
||
26 | public function testValidDirective() |
||
32 | |||
33 | /** |
||
34 | * testDeprecatedForbiddenDirectives |
||
35 | * |
||
36 | * @dataProvider dataDeprecatedForbiddenDirectives |
||
37 | * |
||
38 | * @param string $iniName Name of the ini directive. |
||
39 | * @param string $deprecatedIn The PHP version in which the ini directive was deprecated. |
||
40 | * @param string $forbiddenIn The PHP version in which the ini directive was forbidden. |
||
41 | * @param array $lines The line numbers in the test file which apply to this ini directive. |
||
42 | * @param string $okVersion A PHP version in which the ini directive was still valid. |
||
43 | * @param string $deprecatedVersion Optional PHP version to test deprecation message with - |
||
44 | * if different from the $deprecatedIn version. |
||
45 | * @param string $forbiddenVersion Optional PHP version to test forbidden message with - |
||
46 | * if different from the $forbiddenIn version. |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | public function testDeprecatedForbiddenDirectives($iniName, $deprecatedIn, $forbiddenIn, $lines, $okVersion, $deprecatedVersion = null, $forbiddenVersion = null) |
||
76 | |||
77 | /** |
||
78 | * Data provider. |
||
79 | * |
||
80 | * @see testDeprecatedForbiddenDirectives() |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | public function dataDeprecatedForbiddenDirectives() |
||
108 | |||
109 | |||
110 | /** |
||
111 | * testDeprecatedDirectives |
||
112 | * |
||
113 | * @dataProvider dataDeprecatedDirectives |
||
114 | * |
||
115 | * @param string $iniName Name of the ini directive. |
||
116 | * @param string $deprecatedIn The PHP version in which the ini directive was deprecated. |
||
117 | * @param array $lines The line numbers in the test file which apply to this ini directive. |
||
118 | * @param string $okVersion A PHP version in which the ini directive was still valid. |
||
119 | * @param string $deprecatedVersion Optional PHP version to test deprecation message with - |
||
120 | * if different from the $deprecatedIn version. |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | View Code Duplication | public function testDeprecatedDirectives($iniName, $deprecatedIn, $lines, $okVersion, $deprecatedVersion = null) |
|
141 | |||
142 | /** |
||
143 | * Data provider. |
||
144 | * |
||
145 | * @see testDeprecatedDirectives() |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function dataDeprecatedDirectives() |
||
162 | |||
163 | |||
164 | |||
165 | /** |
||
166 | * testForbiddenWithAlternative |
||
167 | * |
||
168 | * @dataProvider dataForbiddenWithAlternative |
||
169 | * |
||
170 | * @param string $iniName Name of the ini directive. |
||
171 | * @param string $forbiddenIn The PHP version in which the ini directive was forbidden. |
||
172 | * @param string $alternative An alternative ini directive for the forbidden directive. |
||
173 | * @param array $lines The line numbers in the test file which apply to this ini directive. |
||
174 | * @param string $okVersion A PHP version in which the ini directive was still valid. |
||
175 | * @param string $forbiddenVersion Optional PHP version to test forbidden message with - |
||
176 | * if different from the $forbiddenIn version. |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | View Code Duplication | public function testForbiddenWithAlternative($iniName, $forbiddenIn, $alternative, $lines, $okVersion, $forbiddenVersion = null) |
|
196 | |||
197 | /** |
||
198 | * Data provider. |
||
199 | * |
||
200 | * @see testForbiddenWithAlternative() |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | public function dataForbiddenWithAlternative() |
||
212 | |||
213 | /** |
||
214 | * testForbiddenDirectives |
||
215 | * |
||
216 | * @dataProvider dataForbiddenDirectives |
||
217 | * |
||
218 | * @param string $iniName Name of the ini directive. |
||
219 | * @param string $forbiddenIn The PHP version in which the ini directive was forbidden. |
||
220 | * @param array $lines The line numbers in the test file which apply to this ini directive. |
||
221 | * @param string $okVersion A PHP version in which the ini directive was still valid. |
||
222 | * @param string $forbiddenVersion Optional PHP version to test forbidden message with - |
||
223 | * if different from the $forbiddenIn version. |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | View Code Duplication | public function testForbiddenDirectives($iniName, $forbiddenIn, $lines, $okVersion, $forbiddenVersion = null) |
|
243 | |||
244 | /** |
||
245 | * Data provider. |
||
246 | * |
||
247 | * @see testForbiddenDirectives() |
||
248 | * |
||
249 | * @return array |
||
250 | */ |
||
251 | public function dataForbiddenDirectives() |
||
272 | |||
273 | } |
||
274 |
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.