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 | * Identifikační řetězec. |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | public $init = null; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Sloupeček s názvem. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | public $nameColumn = 'nazev'; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Sloupeček obsahující datum vložení záznamu do shopu. |
||
| 94 | * |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | public $myCreateColumn = 'false'; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Slopecek obsahujici datum poslení modifikace záznamu do shopu. |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | public $myLastModifiedColumn = 'lastUpdate'; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Klíčový idendifikátor záznamu. |
||
| 108 | * |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | public $fbKeyColumn = 'id'; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Informace o posledním HTTP requestu. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | public $info; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Informace o poslední HTTP chybě. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | public $error; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Used codes storage. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | public $codes = null; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Last Inserted ID. |
||
| 136 | * |
||
| 137 | * @var int |
||
| 138 | */ |
||
| 139 | public $lastInsertedID = null; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Default Line Prefix. |
||
| 143 | * |
||
| 144 | * @var string |
||
| 145 | */ |
||
| 146 | public $prefix = '/c/'; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * HTTP Response code of last request |
||
| 150 | * |
||
| 151 | * @var int |
||
| 152 | */ |
||
| 153 | public $lastResponseCode = null; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Array of fields for next curl POST operation |
||
| 157 | * |
||
| 158 | * @var array |
||
| 159 | */ |
||
| 160 | protected $postFields = []; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Třída pro práci s FlexiBee. |
||
| 164 | * |
||
| 165 | * @param string $init výchozí selektor dat |
||
| 166 | */ |
||
| 167 | public function __construct($init = null) |
||
| 174 | |||
| 175 | public function curlInit() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Nastaví Agendu pro Komunikaci. |
||
| 190 | * |
||
| 191 | * @param string $evidence |
||
| 192 | */ |
||
| 193 | public function setEvidence($evidence) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Převede rekurzivně Objekt na pole. |
||
| 200 | * |
||
| 201 | * @param object|array $object |
||
| 202 | * |
||
| 203 | * @return array |
||
| 204 | */ |
||
| 205 | public static function object2array($object) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Funkce, která provede I/O operaci a vyhodnotí výsledek. |
||
| 228 | * |
||
| 229 | * @param string $urlSuffix část URL za identifikátorem firmy. |
||
| 230 | * @param string $method HTTP/REST metoda |
||
| 231 | * @param string $format Requested format |
||
| 232 | */ |
||
| 233 | public function performRequest($urlSuffix = null, $method = 'GET', |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Convert XML to array. |
||
| 340 | * |
||
| 341 | * @param string $xml |
||
| 342 | * |
||
| 343 | * @return array |
||
| 344 | */ |
||
| 345 | public static function xml2array($xml) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Odpojení od FlexiBee. |
||
| 367 | */ |
||
| 368 | public function disconnect() |
||
| 375 | |||
| 376 | public function __destruct() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Načte data z FlexiBee. |
||
| 383 | * |
||
| 384 | * @param string $suffix dotaz |
||
| 385 | */ |
||
| 386 | public function loadFlexiData($suffix = null) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Načte řádek dat z FlexiBee. |
||
| 393 | * |
||
| 394 | * @param int $recordID id požadovaného záznamu |
||
| 395 | * |
||
| 396 | * @return array |
||
| 397 | */ |
||
| 398 | public function getFlexiRow($recordID) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Načte data z FlexiBee. |
||
| 411 | * |
||
| 412 | * @param string $suffix dotaz |
||
| 413 | * @param string $conditions Volitelný filtrovací výraz |
||
| 414 | */ |
||
| 415 | public function getFlexiData($suffix = null, $conditions = null) |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Načte záznam z FlexiBee. |
||
| 442 | * |
||
| 443 | * @param int $id ID záznamu |
||
| 444 | * |
||
| 445 | * @return int počet načtených položek |
||
| 446 | */ |
||
| 447 | public function loadFromFlexiBee($id = null) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Převede data do Json formátu pro FlexiBee. |
||
| 458 | * |
||
| 459 | * @param array $data |
||
| 460 | * |
||
| 461 | * @return string |
||
| 462 | */ |
||
| 463 | public function jsonizeData($data) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Test if given record ID exists in FlexiBee. |
||
| 477 | * |
||
| 478 | * @param string|int $identifer |
||
| 479 | */ |
||
| 480 | public function idExists($identifer = null) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Test if given record exists in FlexiBee. |
||
| 493 | * |
||
| 494 | * @param array $data |
||
| 495 | */ |
||
| 496 | public function recordExists($data = null) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Vrací z FlexiBee sloupečky podle podmínek. |
||
| 510 | * |
||
| 511 | * @param array|int|string $conditions pole podmínek nebo ID záznamu |
||
| 512 | * @param array|string $orderBy třídit dle |
||
| 513 | * @param string $indexBy klice vysledku naplnit hodnotou ze |
||
| 514 | * sloupečku |
||
| 515 | * @param int $limit maximální počet vrácených záznamů |
||
| 516 | * |
||
| 517 | * @return array |
||
| 518 | */ |
||
| 519 | public function getAllFromFlexibee($conditions = null, $orderBy = null, |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Vrací z FlexiBee sloupečky podle podmínek. |
||
| 541 | * |
||
| 542 | * @param string[] $columnsList seznam položek |
||
| 543 | * @param array|int|string $conditions pole podmínek nebo ID záznamu |
||
| 544 | * @param array|string $orderBy třídit dle |
||
| 545 | * @param string $indexBy klice vysledku naplnit hodnotou ze |
||
| 546 | * sloupečku |
||
| 547 | * @param int $limit maximální počet vrácených záznamů |
||
| 548 | * |
||
| 549 | * @return array |
||
| 550 | */ |
||
| 551 | public function getColumnsFromFlexibee($columnsList, $conditions = null, |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Vrací kód záznamu. |
||
| 586 | * |
||
| 587 | * @param mixed $data |
||
| 588 | * |
||
| 589 | * @todo papat i string |
||
| 590 | * |
||
| 591 | * @return string |
||
| 592 | */ |
||
| 593 | public function getKod($data = null, $unique = true) |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Vyhledavani v záznamech objektu FlexiBee. |
||
| 649 | * |
||
| 650 | * @param string $what hledaný výraz |
||
| 651 | * |
||
| 652 | * @return array pole výsledků |
||
| 653 | */ |
||
| 654 | public function searchString($what) |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Write Operation Result. |
||
| 710 | * |
||
| 711 | * @param array $resultData |
||
| 712 | * @param string $url URL |
||
| 713 | */ |
||
| 714 | public function logResult($resultData, $url = null) |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Generuje fragment url pro filtrování. |
||
| 758 | * |
||
| 759 | * @see https://www.flexibee.eu/api/dokumentace/ref/filters |
||
| 760 | * |
||
| 761 | * @param array $data |
||
| 762 | * @param string $operator and/or |
||
| 763 | * |
||
| 764 | * @return string |
||
| 765 | */ |
||
| 766 | public static function flexiUrl(array $data, $operator = 'and') |
||
| 783 | } |
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..