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 FlexiBeeRO 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 FlexiBeeRO, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class FlexiBeeRO extends \Ease\Brick |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Základní namespace pro komunikaci s FlexiBEE. |
||
| 15 | * |
||
| 16 | * @var string Jmený prostor datového bloku odpovědi |
||
| 17 | */ |
||
| 18 | public $nameSpace = 'winstrom'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Datový blok v poli odpovědi. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | public $resultField = 'results'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Verze protokolu použitého pro komunikaci. |
||
| 29 | * |
||
| 30 | * @var string Verze použitého API |
||
| 31 | */ |
||
| 32 | public $protoVersion = '1.0'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Evidence užitá objektem. |
||
| 36 | * |
||
| 37 | * @link https://demo.flexibee.eu/c/demo/evidence-list Přehled evidencí |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | public $evidence = null; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Výchozí formát pro komunikaci. |
||
| 44 | * |
||
| 45 | * @link https://www.flexibee.eu/api/dokumentace/ref/format-types Přehled možných formátů |
||
| 46 | * |
||
| 47 | * @var string json|xml|... |
||
| 48 | */ |
||
| 49 | public $format = 'json'; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Curl Handle. |
||
| 53 | * |
||
| 54 | * @var resource |
||
| 55 | */ |
||
| 56 | public $curl = null; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var type |
||
| 60 | */ |
||
| 61 | public $company = FLEXIBEE_COMPANY; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | public $url = FLEXIBEE_URL; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | public $user = FLEXIBEE_LOGIN; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | public $password = FLEXIBEE_PASSWORD; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var array Pole HTTP hlaviček odesílaných s každým požadavkem |
||
| 80 | */ |
||
| 81 | public $defaultHttpHeaders = ['User-Agent: FlexiPeeHP']; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Identifikační řetězec. |
||
| 85 | * |
||
| 86 | * @var string |
||
| 87 | */ |
||
| 88 | public $init = null; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Sloupeček s názvem. |
||
| 92 | * |
||
| 93 | * @var string |
||
| 94 | */ |
||
| 95 | public $nameColumn = 'nazev'; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Sloupeček obsahující datum vložení záznamu do shopu. |
||
| 99 | * |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | public $myCreateColumn = 'false'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Slopecek obsahujici datum poslení modifikace záznamu do shopu. |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | */ |
||
| 109 | public $myLastModifiedColumn = 'lastUpdate'; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Klíčový idendifikátor záznamu. |
||
| 113 | * |
||
| 114 | * @var string |
||
| 115 | */ |
||
| 116 | public $fbKeyColumn = 'id'; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Informace o posledním HTTP requestu. |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | public $info; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Informace o poslední HTTP chybě. |
||
| 127 | * |
||
| 128 | * @var array |
||
| 129 | */ |
||
| 130 | public $error; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Used codes storage. |
||
| 134 | * |
||
| 135 | * @var array |
||
| 136 | */ |
||
| 137 | public $codes = null; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Last Inserted ID. |
||
| 141 | * |
||
| 142 | * @var int |
||
| 143 | */ |
||
| 144 | public $lastInsertedID = null; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Default Line Prefix. |
||
| 148 | * |
||
| 149 | * @var string |
||
| 150 | */ |
||
| 151 | public $prefix = '/c/'; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * HTTP Response code of last request |
||
| 155 | * |
||
| 156 | * @var int |
||
| 157 | */ |
||
| 158 | public $lastResponseCode = null; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Array of fields for next curl POST operation |
||
| 162 | * |
||
| 163 | * @var array |
||
| 164 | */ |
||
| 165 | protected $postFields = []; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Last operation result data or message(s) |
||
| 169 | * |
||
| 170 | * @var array |
||
| 171 | */ |
||
| 172 | public $lastResult = null; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Třída pro práci s FlexiBee. |
||
| 176 | * |
||
| 177 | * @param string $init výchozí selektor dat |
||
| 178 | */ |
||
| 179 | public function __construct($init = null) |
||
| 186 | |||
| 187 | public function curlInit() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Nastaví Agendu pro Komunikaci. |
||
| 202 | * |
||
| 203 | * @param string $evidence |
||
| 204 | */ |
||
| 205 | public function setEvidence($evidence) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Převede rekurzivně Objekt na pole. |
||
| 212 | * |
||
| 213 | * @param object|array $object |
||
| 214 | * |
||
| 215 | * @return array |
||
| 216 | */ |
||
| 217 | public static function object2array($object) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Funkce, která provede I/O operaci a vyhodnotí výsledek. |
||
| 240 | * |
||
| 241 | * @param string $urlSuffix část URL za identifikátorem firmy. |
||
| 242 | * @param string $method HTTP/REST metoda |
||
| 243 | * @param string $format Requested format |
||
| 244 | */ |
||
| 245 | public function performRequest($urlSuffix = null, $method = 'GET', |
||
| 369 | |||
| 370 | public function processRequest() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Convert XML to array. |
||
| 377 | * |
||
| 378 | * @param string $xml |
||
| 379 | * |
||
| 380 | * @return array |
||
| 381 | */ |
||
| 382 | public static function xml2array($xml) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Odpojení od FlexiBee. |
||
| 404 | */ |
||
| 405 | public function disconnect() |
||
| 412 | |||
| 413 | public function __destruct() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Načte data z FlexiBee. |
||
| 420 | * |
||
| 421 | * @param string $suffix dotaz |
||
| 422 | */ |
||
| 423 | public function loadFlexiData($suffix = null) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Načte řádek dat z FlexiBee. |
||
| 430 | * |
||
| 431 | * @param int $recordID id požadovaného záznamu |
||
| 432 | * |
||
| 433 | * @return array |
||
| 434 | */ |
||
| 435 | public function getFlexiRow($recordID) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Načte data z FlexiBee. |
||
| 448 | * |
||
| 449 | * @param string $suffix dotaz |
||
| 450 | * @param string $conditions Volitelný filtrovací výraz |
||
| 451 | */ |
||
| 452 | public function getFlexiData($suffix = null, $conditions = null) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Načte záznam z FlexiBee. |
||
| 479 | * |
||
| 480 | * @param int $id ID záznamu |
||
| 481 | * |
||
| 482 | * @return int počet načtených položek |
||
| 483 | */ |
||
| 484 | public function loadFromFlexiBee($id = null) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Převede data do Json formátu pro FlexiBee. |
||
| 495 | * |
||
| 496 | * @param array $data |
||
| 497 | * |
||
| 498 | * @return string |
||
| 499 | */ |
||
| 500 | public function jsonizeData($data) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Test if given record ID exists in FlexiBee. |
||
| 514 | * |
||
| 515 | * @param string|int $identifer |
||
| 516 | */ |
||
| 517 | public function idExists($identifer = null) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Test if given record exists in FlexiBee. |
||
| 530 | * |
||
| 531 | * @param array $data |
||
| 532 | */ |
||
| 533 | public function recordExists($data = null) |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Vrací z FlexiBee sloupečky podle podmínek. |
||
| 547 | * |
||
| 548 | * @param array|int|string $conditions pole podmínek nebo ID záznamu |
||
| 549 | * @param array|string $orderBy třídit dle |
||
| 550 | * @param string $indexBy klice vysledku naplnit hodnotou ze |
||
| 551 | * sloupečku |
||
| 552 | * @param int $limit maximální počet vrácených záznamů |
||
| 553 | * |
||
| 554 | * @return array |
||
| 555 | */ |
||
| 556 | public function getAllFromFlexibee($conditions = null, $orderBy = null, |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Vrací z FlexiBee sloupečky podle podmínek. |
||
| 578 | * |
||
| 579 | * @param string[] $columnsList seznam položek |
||
| 580 | * @param array|int|string $conditions pole podmínek nebo ID záznamu |
||
| 581 | * @param array|string $orderBy třídit dle |
||
| 582 | * @param string $indexBy klice vysledku naplnit hodnotou ze |
||
| 583 | * sloupečku |
||
| 584 | * @param int $limit maximální počet vrácených záznamů |
||
| 585 | * |
||
| 586 | * @return array |
||
| 587 | */ |
||
| 588 | public function getColumnsFromFlexibee($columnsList, $conditions = null, |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Vrací kód záznamu. |
||
| 623 | * |
||
| 624 | * @param mixed $data |
||
| 625 | * |
||
| 626 | * @todo papat i string |
||
| 627 | * |
||
| 628 | * @return string |
||
| 629 | */ |
||
| 630 | public function getKod($data = null, $unique = true) |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Vyhledavani v záznamech objektu FlexiBee. |
||
| 686 | * |
||
| 687 | * @param string $what hledaný výraz |
||
| 688 | * |
||
| 689 | * @return array pole výsledků |
||
| 690 | */ |
||
| 691 | public function searchString($what) |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Write Operation Result. |
||
| 746 | * |
||
| 747 | * @param array $resultData |
||
| 748 | * @param string $url URL |
||
| 749 | */ |
||
| 750 | public function logResult($resultData = null, $url = null) |
||
| 794 | |||
| 795 | /** |
||
| 796 | * Generuje fragment url pro filtrování. |
||
| 797 | * |
||
| 798 | * @see https://www.flexibee.eu/api/dokumentace/ref/filters |
||
| 799 | * |
||
| 800 | * @param array $data |
||
| 801 | * @param string $operator and/or |
||
| 802 | * |
||
| 803 | * @return string |
||
| 804 | */ |
||
| 805 | public static function flexiUrl(array $data, $operator = 'and') |
||
| 822 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..