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:
Complex classes like FlexiBeeROTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FlexiBeeROTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class FlexiBeeROTest extends \Test\Ease\BrickTest |
||
11 | { |
||
12 | /** |
||
13 | * @var FlexiBeeRO |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * Sets up the fixture, for example, opens a network connection. |
||
19 | * This method is called before a test is executed. |
||
20 | * @covers FlexiPeeHP\FlexiBeeRO::__construct |
||
21 | */ |
||
22 | protected function setUp() |
||
30 | |||
31 | /** |
||
32 | * Tears down the fixture, for example, closes a network connection. |
||
33 | * This method is called after a test is executed. |
||
34 | */ |
||
35 | protected function tearDown() |
||
39 | |||
40 | /** |
||
41 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
42 | */ |
||
43 | public function testCurlInit() |
||
48 | |||
49 | /** |
||
50 | * @covers FlexiPeeHP\FlexiBeeRO::processInit |
||
51 | */ |
||
52 | public function testProcessInit() |
||
63 | |||
64 | /** |
||
65 | * @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
||
66 | */ |
||
67 | public function testSetEvidence() |
||
72 | |||
73 | /** |
||
74 | * @covers FlexiPeeHP\FlexiBeeRO::object2array |
||
75 | */ |
||
76 | public function testObject2array() |
||
86 | |||
87 | /** |
||
88 | * @covers FlexiPeeHP\FlexiBeeRO::objectToID |
||
89 | */ |
||
90 | public function testObjectToID() |
||
102 | |||
103 | /** |
||
104 | * @covers FlexiPeeHP\FlexiBeeRO::performRequest |
||
105 | */ |
||
106 | public function testPerformRequest() |
||
140 | |||
141 | /** |
||
142 | * @covers FlexiPeeHP\FlexiBeeRO::setAction |
||
143 | */ |
||
144 | public function testSetAction() |
||
152 | |||
153 | /** |
||
154 | * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
||
155 | * @depends testInsertToFlexiBee |
||
156 | */ |
||
157 | public function testGetLastInsertedId() |
||
161 | |||
162 | /** |
||
163 | * @covers FlexiPeeHP\FlexiBeeRO::xml2array |
||
164 | */ |
||
165 | public function testXml2array() |
||
182 | |||
183 | /** |
||
184 | * @covers FlexiPeeHP\FlexiBeeRO::disconnect |
||
185 | * |
||
186 | * @depends testPerformRequest |
||
187 | * @depends testLoadFlexiData |
||
188 | * @depends testGetFlexiRow |
||
189 | * @depends testGetFlexiData |
||
190 | * @depends testLoadFromFlexiBee |
||
191 | * @depends testInsertToFlexiBee |
||
192 | * @depends testIdExists |
||
193 | * @depends testRecordExists |
||
194 | * @depends testGetColumnsFromFlexibee |
||
195 | * @depends testSearchString |
||
196 | */ |
||
197 | public function testDisconnect() |
||
202 | |||
203 | /** |
||
204 | * @covers FlexiPeeHP\FlexiBeeRO::__destruct |
||
205 | * @depends testDisconnect |
||
206 | */ |
||
207 | public function testdestruct() |
||
211 | |||
212 | /** |
||
213 | * @covers FlexiPeeHP\FlexiBeeRO::loadFlexiData |
||
214 | * @todo Implement testLoadFlexiData(). |
||
215 | */ |
||
216 | public function testLoadFlexiData() |
||
223 | |||
224 | /** |
||
225 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
||
226 | */ |
||
227 | public function testGetFlexiRow() |
||
232 | |||
233 | /** |
||
234 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
||
235 | */ |
||
236 | public function testGetFlexiData() |
||
268 | |||
269 | /** |
||
270 | * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
||
271 | */ |
||
272 | public function testLoadFromFlexiBee() |
||
277 | |||
278 | /** |
||
279 | * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData |
||
280 | */ |
||
281 | public function testJsonizeData() |
||
289 | |||
290 | /** |
||
291 | * @covers FlexiPeeHP\FlexiBeeRO::idExists |
||
292 | * @todo Implement testIdExists(). |
||
293 | */ |
||
294 | public function testIdExists() |
||
301 | |||
302 | /** |
||
303 | * @covers FlexiPeeHP\FlexiBeeRO::recordExists |
||
304 | */ |
||
305 | public function testRecordExists() |
||
328 | |||
329 | /** |
||
330 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
||
331 | * @todo Implement testGetColumnsFromFlexibee(). |
||
332 | */ |
||
333 | public function testGetColumnsFromFlexibee() |
||
340 | |||
341 | /** |
||
342 | * @covers FlexiPeeHP\FlexiBeeRO::getKod |
||
343 | */ |
||
344 | public function testGetKod() |
||
371 | |||
372 | /** |
||
373 | * @covers FlexiPeeHP\FlexiBeeRO::logResult |
||
374 | */ |
||
375 | public function testLogResult() |
||
396 | |||
397 | /** |
||
398 | * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
||
399 | */ |
||
400 | public function testFlexiUrl() |
||
411 | |||
412 | /** |
||
413 | * @covers FlexiPeeHP\FlexiBeeRO::__toString |
||
414 | */ |
||
415 | public function testtoString() |
||
429 | |||
430 | /** |
||
431 | * @covers FlexiPeeHP\FlexiBeeRO::draw |
||
432 | */ |
||
433 | public function testDraw($whatWant = NULL) |
||
438 | |||
439 | } |
||
440 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: