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 |
||
16 | class FlexiBeeRW extends FlexiBeeRO |
||
17 | { |
||
18 | /** |
||
19 | * Sloupeček obsahující datum vložení záznamu do shopu. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $myCreateColumn = 'false'; |
||
24 | |||
25 | /** |
||
26 | * Slopecek obsahujici datum poslení modifikace záznamu do shopu. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $myLastModifiedColumn = 'lastUpdate'; |
||
31 | |||
32 | /** |
||
33 | * Last Inserted ID. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | public $lastInsertedID = null; |
||
38 | |||
39 | /** |
||
40 | * Array of fields for next curl POST operation |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | public $postFields = null; |
||
45 | |||
46 | /** |
||
47 | * Save record (if evidence allow to). |
||
48 | * Uloží záznam (pokud to evidence dovoluje) |
||
49 | * |
||
50 | * @param array $data Data to save |
||
51 | * @throws Exception Evidence does not support Import |
||
52 | * |
||
53 | * @return array odpověď |
||
54 | */ |
||
55 | public function insertToFlexiBee($data = null) |
||
80 | |||
81 | /** |
||
82 | * Give you last inserted record ID. |
||
83 | * |
||
84 | * @return int |
||
85 | */ |
||
86 | public function getLastInsertedId() |
||
90 | |||
91 | /** |
||
92 | * Smaže záznam |
||
93 | * |
||
94 | * @param int|string $id identifikátor záznamu |
||
95 | * @return boolean Response code is 200 ? |
||
96 | */ |
||
97 | public function deleteFromFlexiBee($id = null) |
||
106 | |||
107 | /** |
||
108 | * Control for existing column names in evidence and take data |
||
109 | * |
||
110 | * @param array $data Data to keep |
||
111 | * @return int number of records taken |
||
112 | * @throws \Exception try to load data to unexistent column |
||
113 | */ |
||
114 | public function takeData($data) |
||
127 | |||
128 | /** |
||
129 | * Control data for mandatory columns presence. |
||
130 | * |
||
131 | * @param array $data |
||
132 | * @return array List of missing columns. Empty if all is ok |
||
133 | */ |
||
134 | View Code Duplication | public function controlMandatoryColumns($data = null) |
|
152 | |||
153 | /** |
||
154 | * Control data for readonly columns presence. |
||
155 | * |
||
156 | * @param array $data |
||
157 | * @return array List of ReadOnly columns. Empty if all is ok |
||
158 | */ |
||
159 | View Code Duplication | public function controlReadOnlyColumns($data = null) |
|
177 | |||
178 | /** |
||
179 | * Convert Timestamp to FlexiBee Date format. |
||
180 | * |
||
181 | * @param int $timpestamp |
||
182 | * |
||
183 | * @return string FlexiBee Date or NULL |
||
184 | */ |
||
185 | View Code Duplication | public static function timestampToFlexiDate($timpestamp = null) |
|
195 | |||
196 | /** |
||
197 | * Convert Timestamp to Flexi DateTime format. |
||
198 | * |
||
199 | * @param int $timpestamp |
||
200 | * |
||
201 | * @return string FlexiBee DateTime or NULL |
||
202 | */ |
||
203 | View Code Duplication | public static function timestampToFlexiDateTime($timpestamp = null) |
|
213 | } |
||
214 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.