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:
| 1 | <?php |
||
| 11 | class FlexiBeeRW extends FlexiBeeRO |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Sloupeček obsahující datum vložení záznamu do shopu. |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | public $myCreateColumn = 'false'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Slopecek obsahujici datum poslení modifikace záznamu do shopu. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | public $myLastModifiedColumn = 'lastUpdate'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Last Inserted ID. |
||
| 29 | * |
||
| 30 | * @var int |
||
| 31 | */ |
||
| 32 | public $lastInsertedID = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Array of fields for next curl POST operation |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | public $postFields = null; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Save record (if evidence allow to). |
||
| 43 | * Uloží záznam (pokud to evidence dovoluje) |
||
| 44 | * |
||
| 45 | * @param array $data Data to save |
||
| 46 | * @throws Exception Evidence does not support Import |
||
| 47 | * |
||
| 48 | * @return array odpověď |
||
| 49 | */ |
||
| 50 | public function insertToFlexiBee($data = null) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Give you last inserted record ID. |
||
| 78 | * |
||
| 79 | * @return int |
||
| 80 | */ |
||
| 81 | public function getLastInsertedId() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Smaže záznam |
||
| 88 | * |
||
| 89 | * @param int|string $id identifikátor záznamu |
||
| 90 | * @return boolean Response code is 200 ? |
||
| 91 | */ |
||
| 92 | public function deleteFromFlexiBee($id = null) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Control for existing column names in evidence and take data |
||
| 104 | * |
||
| 105 | * @param array $data Data to keep |
||
| 106 | * @return int number of records taken |
||
| 107 | * @throws \Exception try to load data to unexistent column |
||
| 108 | */ |
||
| 109 | public function takeData($data) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Control data for mandatory columns presence. |
||
| 124 | * |
||
| 125 | * @param array $data |
||
| 126 | * @return array List of missing columns. Empty if all is ok |
||
| 127 | */ |
||
| 128 | public function controlMandatoryColumns($data = null) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Convert Timestamp to FlexiBee Date format. |
||
| 149 | * |
||
| 150 | * @param int $timpestamp |
||
| 151 | * |
||
| 152 | * @return string FlexiBee Date or NULL |
||
| 153 | */ |
||
| 154 | View Code Duplication | public static function timestampToFlexiDate($timpestamp = null) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Convert Timestamp to Flexi DateTime format. |
||
| 167 | * |
||
| 168 | * @param int $timpestamp |
||
| 169 | * |
||
| 170 | * @return string FlexiBee DateTime or NULL |
||
| 171 | */ |
||
| 172 | View Code Duplication | public static function timestampToFlexiDateTime($timpestamp = null) |
|
| 182 | |||
| 183 | } |
||
| 184 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.