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 RemovedExtensionsSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/removed_extensions.php'; |
||
20 | |||
21 | /** |
||
22 | * Sniffed file |
||
23 | * |
||
24 | * @var PHP_CodeSniffer_File |
||
25 | */ |
||
26 | protected $_sniffFile; |
||
27 | |||
28 | /** |
||
29 | * setUp |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | public function setUp() |
||
39 | |||
40 | |||
41 | /** |
||
42 | * testRemovedExtension |
||
43 | * |
||
44 | * @dataProvider dataRemovedExtension |
||
45 | * |
||
46 | * @param string $extensionName Name of the PHP extension. |
||
47 | * @param string $removedIn The PHP version in which the extension was removed. |
||
48 | * @param array $lines The line numbers in the test file which apply to this extension. |
||
49 | * @param string $okVersion A PHP version in which the extension was still present. |
||
50 | * @param string $removedVersion Optional PHP version to test removal message with - |
||
51 | * if different from the $removedIn version. |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | View Code Duplication | public function testRemovedExtension($extensionName, $removedIn, $lines, $okVersion, $removedVersion = null) |
|
72 | |||
73 | /** |
||
74 | * Data provider. |
||
75 | * |
||
76 | * @see testRemovedExtension() |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function dataRemovedExtension() |
||
110 | |||
111 | |||
112 | /** |
||
113 | * testDeprecatedRemovedExtension |
||
114 | * |
||
115 | * @dataProvider dataDeprecatedRemovedExtension |
||
116 | * |
||
117 | * @param string $extensionName Name of the PHP extension. |
||
118 | * @param string $deprecatedIn The PHP version in which the extension was deprecated. |
||
119 | * @param string $removedIn The PHP version in which the extension was removed. |
||
120 | * @param array $lines The line numbers in the test file which apply to this extension. |
||
121 | * @param string $okVersion A PHP version in which the extension was still present. |
||
122 | * @param string $deprecatedVersion Optional PHP version to test deprecation message with - |
||
123 | * if different from the $deprecatedIn version. |
||
124 | * @param string $removedVersion Optional PHP version to test removal message with - |
||
125 | * if different from the $removedIn version. |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | View Code Duplication | public function testDeprecatedRemovedExtension($extensionName, $deprecatedIn, $removedIn, $lines, $okVersion, $deprecatedVersion = null, $removedVersion = null) |
|
156 | |||
157 | /** |
||
158 | * Data provider. |
||
159 | * |
||
160 | * @see testDeprecatedRemovedExtension() |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | public function dataDeprecatedRemovedExtension() |
||
171 | |||
172 | |||
173 | /** |
||
174 | * testNotAFunctionCall |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | public function testNotAFunctionCall() |
||
182 | |||
183 | /** |
||
184 | * testFunctionDeclaration |
||
185 | * |
||
186 | * @return void |
||
187 | */ |
||
188 | public function testFunctionDeclaration() |
||
192 | |||
193 | /** |
||
194 | * testNewClass |
||
195 | * |
||
196 | * @return void |
||
197 | */ |
||
198 | public function testNewClass() |
||
202 | |||
203 | /** |
||
204 | * testMethod |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | public function testMethod() |
||
212 | |||
213 | /** |
||
214 | * testWhiteListing |
||
215 | * |
||
216 | * @return void |
||
217 | */ |
||
218 | public function testWhiteListing() |
||
222 | } |
||
223 |
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.