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() |
||
23 | { |
||
24 | $this->object = new FlexiBeeRO(); |
||
25 | $this->object->prefix = ''; |
||
26 | $this->object->company = ''; |
||
27 | $this->object->debug = true; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Tears down the fixture, for example, closes a network connection. |
||
32 | * This method is called after a test is executed. |
||
33 | */ |
||
34 | protected function tearDown() |
||
38 | |||
39 | public function testConstructor() |
||
64 | |||
65 | /** |
||
66 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
67 | */ |
||
68 | public function testSetupProperty() |
||
75 | |||
76 | /** |
||
77 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
78 | */ |
||
79 | public function testCurlInit() |
||
84 | |||
85 | /** |
||
86 | * @covers FlexiPeeHP\FlexiBeeRO::processInit |
||
87 | */ |
||
88 | public function testProcessInit() |
||
89 | { |
||
90 | $this->object->processInit(['id' => 1]); |
||
91 | $this->assertEquals(1, $this->object->getDataValue('id')); |
||
92 | if (!is_null($this->object->evidence) && $this->object->evidence != 'test') { |
||
93 | $firstID = $this->object->getColumnsFromFlexibee('id', |
||
|
|||
94 | ['limit' => 1]); |
||
95 | |||
96 | if (count($firstID)) { |
||
97 | |||
98 | $this->object->processInit((int) current($firstID)); |
||
99 | $this->assertNotEmpty($this->object->__toString()); |
||
100 | |||
101 | if (isset($firstID[0]['kod'])) { |
||
102 | $this->object->processInit('code:'.$firstID[0]['kod']); |
||
103 | $this->assertNotEmpty($this->object->__toString()); |
||
104 | } |
||
105 | } else { |
||
106 | $this->markTestSkipped(sprintf('Evidence %s doed not contain first record', |
||
107 | $this->object->getEvidence())); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @covers FlexiPeeHP\FlexiBeeRO::setUp |
||
114 | */ |
||
115 | public function testSetUp() |
||
116 | { |
||
117 | $this->object->setUp( |
||
118 | [ |
||
119 | 'company' => 'cmp', |
||
120 | 'url' => 'url', |
||
121 | 'user' => 'usr', |
||
122 | 'password' => 'pwd', |
||
123 | 'prefix' => 'c', |
||
124 | 'debug' => true, |
||
125 | 'defaultUrlParams' => ['limit' => 10], |
||
126 | 'evidence' => 'smlouva' |
||
127 | ] |
||
128 | ); |
||
129 | $this->assertEquals('cmp', $this->object->company); |
||
130 | $this->assertEquals('url', $this->object->url); |
||
131 | $this->assertEquals('usr', $this->object->user); |
||
132 | $this->assertEquals('/c/', $this->object->prefix); |
||
133 | $this->assertEquals('pwd', $this->object->password); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @covers FlexiPeeHP\FlexiBeeRO::setPrefix |
||
138 | * @expectedException \Exception |
||
139 | */ |
||
140 | public function testSetPrefix() |
||
148 | |||
149 | /** |
||
150 | * @covers FlexiPeeHP\FlexiBeeRO::setFormat |
||
151 | */ |
||
152 | public function testSetFormat() |
||
157 | |||
158 | /** |
||
159 | * We can set only evidence defined in EvidenceList class |
||
160 | * |
||
161 | * @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
||
162 | * @expectedException \Exception |
||
163 | */ |
||
164 | public function testSetEvidence() |
||
171 | |||
172 | /** |
||
173 | * @covers FlexiPeeHP\FlexiBeeRO::setCompany |
||
174 | */ |
||
175 | public function testSetCompany() |
||
180 | |||
181 | /** |
||
182 | * @covers FlexiPeeHP\FlexiBeeRO::object2array |
||
183 | */ |
||
184 | public function testObject2array() |
||
194 | |||
195 | /** |
||
196 | * @covers FlexiPeeHP\FlexiBeeRO::objectToID |
||
197 | */ |
||
198 | public function testObjectToID() |
||
210 | |||
211 | /** |
||
212 | * @covers FlexiPeeHP\FlexiBeeRO::performRequest |
||
213 | */ |
||
214 | public function testPerformRequest() |
||
245 | |||
246 | /** |
||
247 | * @covers FlexiPeeHP\FlexiBeeRO::setAction |
||
248 | */ |
||
249 | public function testSetAction() |
||
269 | |||
270 | /** |
||
271 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidence |
||
272 | */ |
||
273 | public function testGetEvidence() |
||
278 | |||
279 | /** |
||
280 | * @covers FlexiPeeHP\FlexiBeeRO::getCompany |
||
281 | */ |
||
282 | public function testGetCompany() |
||
286 | |||
287 | /** |
||
288 | * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence |
||
289 | */ |
||
290 | public function testGetResponseEvidence() |
||
295 | |||
296 | /** |
||
297 | * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
||
298 | * @depends testInsertToFlexiBee |
||
299 | */ |
||
300 | public function testGetLastInsertedId() |
||
304 | |||
305 | /** |
||
306 | * @covers FlexiPeeHP\FlexiBeeRO::xml2array |
||
307 | */ |
||
308 | public function testXml2array() |
||
325 | |||
326 | /** |
||
327 | * @covers FlexiPeeHP\FlexiBeeRO::disconnect |
||
328 | * |
||
329 | * @depends testPerformRequest |
||
330 | * @depends testLoadFlexiData |
||
331 | * @depends testGetFlexiRow |
||
332 | * @depends testGetFlexiData |
||
333 | * @depends testLoadFromFlexiBee |
||
334 | * @depends testInsertToFlexiBee |
||
335 | * @depends testIdExists |
||
336 | * @depends testRecordExists |
||
337 | * @depends testGetColumnsFromFlexibee |
||
338 | * @depends testSearchString |
||
339 | */ |
||
340 | public function testDisconnect() |
||
345 | |||
346 | /** |
||
347 | * @covers FlexiPeeHP\FlexiBeeRO::__destruct |
||
348 | * @depends testDisconnect |
||
349 | */ |
||
350 | public function testdestruct() |
||
354 | |||
355 | /** |
||
356 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
||
357 | */ |
||
358 | public function testGetFlexiRow() |
||
363 | |||
364 | /** |
||
365 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
||
366 | */ |
||
367 | public function testGetFlexiData() |
||
400 | |||
401 | /** |
||
402 | * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
||
403 | */ |
||
404 | public function testLoadFromFlexiBee() |
||
409 | |||
410 | /** |
||
411 | * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData |
||
412 | */ |
||
413 | public function testJsonizeData() |
||
434 | |||
435 | /** |
||
436 | * @covers FlexiPeeHP\FlexiBeeRO::idExists |
||
437 | */ |
||
438 | public function testIdExists() |
||
462 | |||
463 | /** |
||
464 | * @covers FlexiPeeHP\FlexiBeeRO::getRecordID |
||
465 | */ |
||
466 | public function testGetRecordID() |
||
473 | |||
474 | /** |
||
475 | * @covers FlexiPeeHP\FlexiBeeRO::recordExists |
||
476 | */ |
||
477 | public function testRecordExists() |
||
510 | |||
511 | /** |
||
512 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
||
513 | */ |
||
514 | public function testGetColumnsFromFlexibee() |
||
532 | |||
533 | /** |
||
534 | * @covers FlexiPeeHP\FlexiBeeRO::getExternalID |
||
535 | */ |
||
536 | public function testGetExternalID() |
||
546 | |||
547 | /** |
||
548 | * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion |
||
549 | */ |
||
550 | public function testGetGlobalVersion() |
||
567 | |||
568 | /** |
||
569 | * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat |
||
570 | */ |
||
571 | public function testGetResponseFormat() |
||
580 | |||
581 | /** |
||
582 | * @covers FlexiPeeHP\FlexiBeeRO::getKod |
||
583 | */ |
||
584 | public function testGetKod() |
||
611 | |||
612 | /** |
||
613 | * @covers FlexiPeeHP\FlexiBeeRO::logResult |
||
614 | */ |
||
615 | public function testLogResult() |
||
636 | |||
637 | /** |
||
638 | * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
||
639 | */ |
||
640 | public function testFlexiUrl() |
||
651 | |||
652 | /** |
||
653 | * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat |
||
654 | */ |
||
655 | public function testunifyResponseFormat() |
||
696 | |||
697 | /** |
||
698 | * @covers FlexiPeeHP\FlexiBeeRO::__toString |
||
699 | */ |
||
700 | public function testtoString() |
||
714 | |||
715 | /** |
||
716 | * @covers FlexiPeeHP\FlexiBeeRO::draw |
||
717 | */ |
||
718 | public function testDraw($whatWant = NULL) |
||
723 | |||
724 | /** |
||
725 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo |
||
726 | */ |
||
727 | View Code Duplication | public function testgetColumnsInfo() |
|
746 | |||
747 | /** |
||
748 | * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo |
||
749 | */ |
||
750 | View Code Duplication | public function testgetActionsInfo() |
|
769 | |||
770 | /** |
||
771 | * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo |
||
772 | */ |
||
773 | View Code Duplication | public function testgetRelationsInfo() |
|
794 | |||
795 | /** |
||
796 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl |
||
797 | */ |
||
798 | public function testgetEvidenceUrl() |
||
803 | |||
804 | /** |
||
805 | * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName |
||
806 | */ |
||
807 | public function testevidenceToClassName() |
||
812 | |||
813 | /** |
||
814 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo |
||
815 | */ |
||
816 | View Code Duplication | public function testGetEvidenceInfo() |
|
833 | |||
834 | /** |
||
835 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName |
||
836 | */ |
||
837 | public function testGetEvidenceName() |
||
853 | |||
854 | /** |
||
855 | * @covers FlexiPeeHP\FlexiBeeRO::performAction |
||
856 | * @expectedException \Exception |
||
857 | */ |
||
858 | public function testPerformAction() |
||
873 | |||
874 | /** |
||
875 | * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile |
||
876 | */ |
||
877 | public function testSaveResponseToFile() |
||
883 | |||
884 | /** |
||
885 | * @covers FlexiPeeHP\FlexiBeeRO::getFirstRecordID() |
||
886 | */ |
||
887 | View Code Duplication | public function testgetFirstRecordID() |
|
908 | |||
909 | /** |
||
910 | * @covers FlexiPeeHP\Adresar::getVazby |
||
911 | * @expectedException \Exception |
||
912 | */ |
||
913 | public function testGetVazby() |
||
941 | |||
942 | /** |
||
943 | * @covers FlexiPeeHP\Adresar::evidenceUrlWithSuffix |
||
944 | */ |
||
945 | public function testEvidenceUrlWithSuffix() |
||
955 | } |
||
956 |
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: