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 |
||
17 | class DefaultControllerTest extends RestTestCase |
||
18 | { |
||
19 | /** |
||
20 | * Initial setup |
||
21 | * @return void |
||
22 | */ |
||
23 | public function setUp() |
||
34 | |||
35 | /** |
||
36 | * test options request |
||
37 | * @return void |
||
38 | */ |
||
39 | View Code Duplication | public function testOptions() |
|
47 | |||
48 | /** |
||
49 | * Testing basic functionality |
||
50 | * @return void |
||
51 | */ |
||
52 | View Code Duplication | public function testIndex() |
|
93 | |||
94 | /** |
||
95 | * Testing basic functionality |
||
96 | * @return void |
||
97 | */ |
||
98 | public function testApp2Index() |
||
111 | |||
112 | /** |
||
113 | * Testing basic functionality |
||
114 | * @return void |
||
115 | */ |
||
116 | View Code Duplication | public function testCustomerCreateDateFilteringIndex() |
|
158 | |||
159 | /** |
||
160 | * test to see if required params are required |
||
161 | * |
||
162 | * @return void |
||
163 | */ |
||
164 | public function testMissingParamExceptions() |
||
171 | |||
172 | /** |
||
173 | * test to see application of param |
||
174 | * |
||
175 | * @dataProvider paramHandlingWithIntDataProvider |
||
176 | * |
||
177 | * @param int $yearFrom year from |
||
178 | * @param int $yearTo year to |
||
179 | * @param int $numRecords number of records |
||
180 | * |
||
181 | * @return void |
||
182 | */ |
||
183 | public function testParamHandlingWithInt($yearFrom, $yearTo, $numRecords) |
||
190 | |||
191 | /** |
||
192 | * data provider |
||
193 | * |
||
194 | * @return array data |
||
|
|||
195 | */ |
||
196 | View Code Duplication | public function paramHandlingWithIntDataProvider() |
|
221 | |||
222 | /** |
||
223 | * test to see application of param with int on string field, if the correct records are returned |
||
224 | * |
||
225 | * @dataProvider paramHandlingWithIntOnStringFieldDataProvider |
||
226 | * |
||
227 | * @param string $groupId group id |
||
228 | * @param int $numRecords number of records |
||
229 | * @param array $idList list of ids |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | public function testParamHandlingWithIntOnStringField($groupId, $numRecords, $idList) |
||
244 | |||
245 | /** |
||
246 | * data provider |
||
247 | * |
||
248 | * @return array data |
||
249 | */ |
||
250 | public function paramHandlingWithIntOnStringFieldDataProvider() |
||
265 | |||
266 | /** |
||
267 | * test to see if the params are mentioned in the schema |
||
268 | * |
||
269 | * @return void |
||
270 | */ |
||
271 | public function testParamsInSchema() |
||
280 | } |
||
281 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.