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\SandTest |
||
11 | { |
||
12 | /** |
||
13 | * @var FlexiBeeRO |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * Example JSON |
||
19 | * @var string json |
||
20 | */ |
||
21 | public $json = '{"winstrom":{"@version":"1.0","adresar":[{"id":"2574","kontakty":[{"id":"299"}]}]}}'; |
||
22 | |||
23 | /** |
||
24 | * Example XML |
||
25 | * @var string xml |
||
26 | */ |
||
27 | public $xml = '<?xml version="1.0" encoding="utf-8"?> |
||
28 | |||
29 | <winstrom version="1.0"> |
||
30 | <!-- Adresář --> |
||
31 | <adresar> |
||
32 | <!-- ID (celé číslo) - --> |
||
33 | <id>2574</id> |
||
34 | <kontakty> |
||
35 | <!-- Kontakty --> |
||
36 | <kontakt> |
||
37 | <!-- ID (celé číslo) - --> |
||
38 | <id>299</id> |
||
39 | </kontakt> |
||
40 | </kontakty> |
||
41 | </adresar> |
||
42 | </winstrom>'; |
||
43 | |||
44 | /** |
||
45 | * Sets up the fixture, for example, opens a network connection. |
||
46 | * This method is called before a test is executed. |
||
47 | * @covers FlexiPeeHP\FlexiBeeRO::__construct |
||
48 | */ |
||
49 | protected function setUp() |
||
56 | |||
57 | /** |
||
58 | * Tears down the fixture, for example, closes a network connection. |
||
59 | * This method is called after a test is executed. |
||
60 | */ |
||
61 | protected function tearDown() |
||
65 | |||
66 | /** |
||
67 | * @covers FlexiPeeHP\FlexiBeeRO::logBanner |
||
68 | */ |
||
69 | public function testLogBanner() |
||
73 | |||
74 | /** |
||
75 | * Test Constructor |
||
76 | * |
||
77 | * @depends testLogBanner |
||
78 | * @covers FlexiPeeHP\FlexiBeeRO::__construct |
||
79 | */ |
||
80 | public function testConstructor() |
||
105 | |||
106 | /** |
||
107 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
108 | */ |
||
109 | public function testSetupProperty() |
||
117 | |||
118 | /** |
||
119 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
120 | */ |
||
121 | public function testCurlInit() |
||
127 | |||
128 | /** |
||
129 | * @covers FlexiPeeHP\FlexiBeeRO::processInit |
||
130 | */ |
||
131 | public function testProcessInit() |
||
160 | |||
161 | /** |
||
162 | * @covers FlexiPeeHP\FlexiBeeRO::setUp |
||
163 | */ |
||
164 | public function testSetUp() |
||
189 | |||
190 | /** |
||
191 | * @covers FlexiPeeHP\FlexiBeeRO::getConnectionOptions |
||
192 | */ |
||
193 | public function testGetConnectionOptions() |
||
202 | |||
203 | /** |
||
204 | * @covers FlexiPeeHP\FlexiBeeRO::setPrefix |
||
205 | * @expectedException \Exception |
||
206 | */ |
||
207 | public function testSetPrefix() |
||
215 | |||
216 | /** |
||
217 | * @covers FlexiPeeHP\FlexiBeeRO::setFormat |
||
218 | */ |
||
219 | public function testSetFormat() |
||
224 | |||
225 | /** |
||
226 | * We can set only evidence defined in EvidenceList class |
||
227 | * |
||
228 | * @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
||
229 | * @expectedException \Exception |
||
230 | */ |
||
231 | public function testSetEvidence() |
||
239 | |||
240 | /** |
||
241 | * @covers FlexiPeeHP\FlexiBeeRO::setCompany |
||
242 | */ |
||
243 | public function testSetCompany() |
||
248 | |||
249 | /** |
||
250 | * @covers FlexiPeeHP\FlexiBeeRO::object2array |
||
251 | */ |
||
252 | public function testObject2array() |
||
262 | |||
263 | /** |
||
264 | * @covers FlexiPeeHP\FlexiBeeRO::objectToID |
||
265 | */ |
||
266 | public function testObjectToID() |
||
274 | |||
275 | /** |
||
276 | * @covers FlexiPeeHP\FlexiBeeRO::performRequest |
||
277 | */ |
||
278 | public function testPerformRequest() |
||
306 | |||
307 | /** |
||
308 | * @covers FlexiPeeHP\FlexiBeeRO::rawResponseToArray |
||
309 | */ |
||
310 | public function testRawResponseToArray() |
||
322 | |||
323 | /** |
||
324 | * @covers FlexiPeeHP\FlexiBeeRO::rawJsonToArray |
||
325 | */ |
||
326 | public function testRawJsonToArray() |
||
346 | |||
347 | /** |
||
348 | * @covers FlexiPeeHP\FlexiBeeRO::rawXmlToArray |
||
349 | */ |
||
350 | public function testRawXmlToArray() |
||
372 | |||
373 | /** |
||
374 | * @covers FlexiPeeHP\FlexiBeeRO::parseResponse |
||
375 | */ |
||
376 | public function testParseResponse() |
||
381 | |||
382 | /** |
||
383 | * @covers FlexiPeeHP\FlexiBeeRO::doCurlRequest |
||
384 | */ |
||
385 | public function testDoCurlRequest() |
||
389 | |||
390 | /** |
||
391 | * @covers FlexiPeeHP\FlexiBeeRO::setAction |
||
392 | */ |
||
393 | public function testSetAction() |
||
414 | |||
415 | /** |
||
416 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidence |
||
417 | */ |
||
418 | public function testGetEvidence() |
||
423 | |||
424 | /** |
||
425 | * @covers FlexiPeeHP\FlexiBeeRO::getCompany |
||
426 | */ |
||
427 | public function testGetCompany() |
||
431 | |||
432 | /** |
||
433 | * @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence |
||
434 | */ |
||
435 | View Code Duplication | public function testGetResponseEvidence() |
|
453 | |||
454 | /** |
||
455 | * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
||
456 | * @depends testInsertToFlexiBee |
||
457 | */ |
||
458 | public function testGetLastInsertedId() |
||
462 | |||
463 | /** |
||
464 | * @covers FlexiPeeHP\FlexiBeeRO::xml2array |
||
465 | */ |
||
466 | public function testXml2array() |
||
487 | |||
488 | /** |
||
489 | * @covers FlexiPeeHP\FlexiBeeRO::extractUrlParams |
||
490 | */ |
||
491 | public function testExtractUrlParams() |
||
498 | |||
499 | /** |
||
500 | * @covers FlexiPeeHP\FlexiBeeRO::urlEncode |
||
501 | */ |
||
502 | public function testUrlEncode() |
||
507 | |||
508 | /** |
||
509 | * @covers FlexiPeeHP\FlexiBeeRO::getAllFromFlexibee |
||
510 | */ |
||
511 | public function testGetAllFromFlexibee() |
||
515 | |||
516 | /** |
||
517 | * @covers FlexiPeeHP\FlexiBeeRO::disconnect |
||
518 | * |
||
519 | * @depends testPerformRequest |
||
520 | * @depends testLoadFlexiData |
||
521 | * @depends testGetFlexiRow |
||
522 | * @depends testGetFlexiData |
||
523 | * @depends testLoadFromFlexiBee |
||
524 | * @depends testInsertToFlexiBee |
||
525 | * @depends testIdExists |
||
526 | * @depends testRecordExists |
||
527 | * @depends testGetColumnsFromFlexibee |
||
528 | * @depends testSearchString |
||
529 | */ |
||
530 | public function testDisconnect() |
||
535 | |||
536 | /** |
||
537 | * @covers FlexiPeeHP\FlexiBeeRO::__destruct |
||
538 | * @depends testDisconnect |
||
539 | */ |
||
540 | public function testdestruct() |
||
544 | |||
545 | /** |
||
546 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
||
547 | */ |
||
548 | public function testGetFlexiRow() |
||
553 | |||
554 | /** |
||
555 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
||
556 | */ |
||
557 | public function testGetFlexiData() |
||
598 | |||
599 | /** |
||
600 | * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
||
601 | */ |
||
602 | public function testLoadFromFlexiBee() |
||
607 | |||
608 | /** |
||
609 | * @covers FlexiPeeHP\FlexiBeeRO::getJsonizedData |
||
610 | */ |
||
611 | public function testGetJsonizedData() |
||
637 | |||
638 | /** |
||
639 | * @covers FlexiPeeHP\FlexiBeeRO::getDataForJSON |
||
640 | */ |
||
641 | public function testGetDataForJson() |
||
645 | |||
646 | /** |
||
647 | * @covers FlexiPeeHP\FlexiBeeRO::idExists |
||
648 | */ |
||
649 | public function testIdExists() |
||
673 | |||
674 | /** |
||
675 | * @covers FlexiPeeHP\FlexiBeeRO::getRecordID |
||
676 | */ |
||
677 | public function testGetRecordID() |
||
682 | |||
683 | /** |
||
684 | * @covers FlexiPeeHP\FlexiBeeRO::recordExists |
||
685 | */ |
||
686 | public function testRecordExists() |
||
718 | |||
719 | /** |
||
720 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
||
721 | */ |
||
722 | public function testGetColumnsFromFlexibee() |
||
743 | |||
744 | /** |
||
745 | * @covers FlexiPeeHP\FlexiBeeRO::getExternalID |
||
746 | */ |
||
747 | public function testGetExternalID() |
||
757 | |||
758 | /** |
||
759 | * @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion |
||
760 | */ |
||
761 | View Code Duplication | public function testGetGlobalVersion() |
|
780 | |||
781 | /** |
||
782 | * @covers FlexiPeeHP\FlexiBeeRO::getApiURL |
||
783 | */ |
||
784 | public function testGetApiUrl() |
||
797 | |||
798 | /** |
||
799 | * @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat |
||
800 | */ |
||
801 | public function testGetResponseFormat() |
||
812 | |||
813 | /** |
||
814 | * @covers FlexiPeeHP\FlexiBeeRO::getKod |
||
815 | */ |
||
816 | public function testGetKod() |
||
844 | |||
845 | /** |
||
846 | * @covers FlexiPeeHP\FlexiBeeRO::logResult |
||
847 | */ |
||
848 | public function testLogResult() |
||
869 | |||
870 | /** |
||
871 | * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
||
872 | */ |
||
873 | public function testFlexiUrl() |
||
884 | |||
885 | /** |
||
886 | * @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat |
||
887 | */ |
||
888 | public function testunifyResponseFormat() |
||
929 | |||
930 | /** |
||
931 | * @covers FlexiPeeHP\FlexiBeeRO::__toString |
||
932 | */ |
||
933 | public function testtoString() |
||
949 | |||
950 | /** |
||
951 | * @covers FlexiPeeHP\FlexiBeeRO::draw |
||
952 | */ |
||
953 | public function testDraw($whatWant = NULL) |
||
958 | |||
959 | /** |
||
960 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo |
||
961 | */ |
||
962 | public function testgetColumnsInfo() |
||
979 | |||
980 | /** |
||
981 | * @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo |
||
982 | */ |
||
983 | public function testgetActionsInfo() |
||
1003 | |||
1004 | /** |
||
1005 | * @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo |
||
1006 | */ |
||
1007 | public function testgetRelationsInfo() |
||
1027 | |||
1028 | /** |
||
1029 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl |
||
1030 | */ |
||
1031 | public function testgetEvidenceUrl() |
||
1036 | |||
1037 | /** |
||
1038 | * @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName |
||
1039 | */ |
||
1040 | public function testevidenceToClassName() |
||
1045 | |||
1046 | /** |
||
1047 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo |
||
1048 | */ |
||
1049 | View Code Duplication | public function testGetEvidenceInfo() |
|
1066 | |||
1067 | /** |
||
1068 | * @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName |
||
1069 | */ |
||
1070 | View Code Duplication | public function testGetEvidenceName() |
|
1087 | |||
1088 | /** |
||
1089 | * @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile |
||
1090 | */ |
||
1091 | public function testSaveResponseToFile() |
||
1097 | |||
1098 | /** |
||
1099 | * @covers FlexiPeeHP\FlexiBeeRO::getFirstRecordID() |
||
1100 | */ |
||
1101 | View Code Duplication | public function testgetFirstRecordID() |
|
1117 | |||
1118 | /** |
||
1119 | * @covers FlexiPeeHP\FlexiBeeRO::getVazby |
||
1120 | * @expectedException \Exception |
||
1121 | */ |
||
1122 | View Code Duplication | public function testGetVazby() |
|
1139 | |||
1140 | /** |
||
1141 | * @covers FlexiPeeHP\FlexiBeeRO::evidenceUrlWithSuffix |
||
1142 | */ |
||
1143 | public function testEvidenceUrlWithSuffix() |
||
1153 | |||
1154 | /** |
||
1155 | * @covers FlexiPeeHP\FlexiBeeRO::join |
||
1156 | * @expectedException \Ease\Exception |
||
1157 | */ |
||
1158 | public function testJoin() |
||
1167 | |||
1168 | /** |
||
1169 | * @covers FlexiPeeHP\FlexiBeeRO::addUrlParams |
||
1170 | */ |
||
1171 | public function testAddUrlParams() |
||
1177 | |||
1178 | /** |
||
1179 | * @covers FlexiPeeHP\FlexiBeeRO::addDefaultUrlParams |
||
1180 | */ |
||
1181 | public function testAddDefaultUrlParams() |
||
1190 | |||
1191 | public function testFlexiDateToDateTime() |
||
1196 | |||
1197 | public function testFlexiDateTimeToDateTime() |
||
1202 | |||
1203 | /** |
||
1204 | * @covers FlexiPeeHP\FlexiBeeRO::setDataValue |
||
1205 | */ |
||
1206 | public function testSetDataValue() |
||
1215 | |||
1216 | /** |
||
1217 | * @covers FlexiPeeHP\FlexiBeeRO::saveDebugFiles |
||
1218 | */ |
||
1219 | public function testSaveDebugFiles() |
||
1223 | |||
1224 | /** |
||
1225 | * @covers FlexiPeeHP\FlexiBeeRO::setPostFields |
||
1226 | * @covers FlexiPeeHP\FlexiBeeRO::getPostFields |
||
1227 | */ |
||
1228 | public function testSetPostFields() |
||
1233 | |||
1234 | /** |
||
1235 | * PHP Date object to FlexiBee date format test |
||
1236 | * |
||
1237 | * @covers FlexiPeeHP\FlexiBeeRO::dateToFlexiDate |
||
1238 | */ |
||
1239 | public function testDateToFlexiDate() |
||
1245 | |||
1246 | /** |
||
1247 | * PHP Date object to FlexiBee dateTime format test |
||
1248 | * |
||
1249 | * @covers FlexiPeeHP\FlexiBeeRO::dateToFlexiDateTime |
||
1250 | */ |
||
1251 | public function testDateToFlexiDateTime() |
||
1257 | |||
1258 | public function testSetFilter() |
||
1263 | |||
1264 | /** |
||
1265 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnInfo |
||
1266 | */ |
||
1267 | public function testGetColumnInfo() |
||
1271 | |||
1272 | /** |
||
1273 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiBeeURL |
||
1274 | */ |
||
1275 | public function testGetFlexiBeeURL() |
||
1279 | |||
1280 | /** |
||
1281 | * @covers FlexiPeeHP\FlexiBeeRO::error500Reporter |
||
1282 | */ |
||
1283 | public function testError500Reporter() |
||
1288 | |||
1289 | /** |
||
1290 | * @covers FlexiPeeHP\FlexiBeeRO::setMyKey |
||
1291 | */ |
||
1292 | public function testSetMyKey() |
||
1296 | |||
1297 | /** |
||
1298 | * @covers FlexiPeeHP\FlexiBeeRO::ignore404 |
||
1299 | */ |
||
1300 | public function testIgnore404() |
||
1305 | |||
1306 | /** |
||
1307 | * @covers FlexiPeeHP\FlexiBeeRO::sendByMail |
||
1308 | */ |
||
1309 | public function testSendByMail() |
||
1314 | |||
1315 | /** |
||
1316 | * @covers FlexiPeeHP\FlexiBeeRO::sendUnsent |
||
1317 | */ |
||
1318 | public function testSendUnsent() |
||
1322 | |||
1323 | /** |
||
1324 | * @covers FlexiPeeHP\FlexiBeeRO::getInFormat |
||
1325 | */ |
||
1326 | public function testGetInFormat() |
||
1331 | |||
1332 | /** |
||
1333 | * @covers FlexiPeeHP\FlexiBeeRO::downloadInFormat |
||
1334 | */ |
||
1335 | public function testDownloadInFormat() |
||
1339 | |||
1340 | /** |
||
1341 | * @covers FlexiPeeHP\FlexiBeeRO::code |
||
1342 | */ |
||
1343 | public function testCode() |
||
1347 | |||
1348 | /** |
||
1349 | * @covers FlexiPeeHP\FlexiBeeRO::uncode |
||
1350 | */ |
||
1351 | public function testUncode() |
||
1355 | |||
1356 | /** |
||
1357 | * @covers FlexiPeeHP\FlexiBeeRO::arrayCleanUP |
||
1358 | */ |
||
1359 | public function testArrayCleanUP() |
||
1364 | |||
1365 | /** |
||
1366 | * @covers FlexiPeeHP\FlexiBeeRO::__wakeup |
||
1367 | */ |
||
1368 | public function test__wakeup() |
||
1372 | |||
1373 | /** |
||
1374 | * @covers FlexiPeeHP\FlexiBeeRO::__destruct |
||
1375 | */ |
||
1376 | public function test_destruct() |
||
1380 | } |
||
1381 |
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: