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 |
||
26 | class ClientLocal extends AbstractClient |
||
27 | { |
||
28 | /** |
||
29 | * @var BaseTableGateway[] |
||
30 | */ |
||
31 | protected $tableGateways = []; |
||
32 | |||
33 | /** |
||
34 | * @var Connection |
||
35 | */ |
||
36 | protected $connection = null; |
||
37 | |||
38 | /** |
||
39 | * ClientLocal constructor. |
||
40 | * |
||
41 | * @param $connection |
||
42 | */ |
||
43 | public function __construct($connection) |
||
47 | |||
48 | /** |
||
49 | * @inheritDoc |
||
50 | */ |
||
51 | public function getTables(array $params = []) |
||
55 | |||
56 | /** |
||
57 | * @inheritDoc |
||
58 | */ |
||
59 | public function getTable($tableName) |
||
63 | |||
64 | /** |
||
65 | * @inheritDoc |
||
66 | */ |
||
67 | public function getColumns($tableName, array $params = []) |
||
71 | |||
72 | /** |
||
73 | * @inheritDoc |
||
74 | */ |
||
75 | public function getColumn($tableName, $columnName) |
||
79 | |||
80 | /** |
||
81 | * @inheritDoc |
||
82 | */ |
||
83 | public function getEntries($tableName, array $params = []) |
||
89 | |||
90 | /** |
||
91 | * @inheritDoc |
||
92 | */ |
||
93 | public function getEntry($tableName, $id, array $params = []) |
||
100 | |||
101 | /** |
||
102 | * @inheritDoc |
||
103 | */ |
||
104 | public function getUsers(array $params = []) |
||
109 | |||
110 | /** |
||
111 | * @inheritDoc |
||
112 | */ |
||
113 | public function getUser($id, array $params = []) |
||
117 | |||
118 | /** |
||
119 | * @inheritDoc |
||
120 | */ |
||
121 | public function getGroups(array $params = []) |
||
125 | |||
126 | /** |
||
127 | * @inheritDoc |
||
128 | */ |
||
129 | public function getGroup($id, array $params = []) |
||
133 | |||
134 | /** |
||
135 | * @inheritDoc |
||
136 | */ |
||
137 | public function getGroupPrivileges($groupID) |
||
145 | |||
146 | /** |
||
147 | * @inheritDoc |
||
148 | */ |
||
149 | public function getFiles(array $params = []) |
||
153 | |||
154 | /** |
||
155 | * @inheritDoc |
||
156 | */ |
||
157 | public function getFile($id, array $params = []) |
||
161 | |||
162 | /** |
||
163 | * @inheritDoc |
||
164 | */ |
||
165 | public function getSettings() |
||
169 | |||
170 | /** |
||
171 | * @inheritDoc |
||
172 | */ |
||
173 | public function getSettingsByCollection($collectionName) |
||
181 | |||
182 | /** |
||
183 | * @inheritDoc |
||
184 | */ |
||
185 | public function getMessages($userId) |
||
192 | |||
193 | /** |
||
194 | * @inheritDoc |
||
195 | */ |
||
196 | View Code Duplication | public function createEntry($tableName, array $data) |
|
204 | |||
205 | /** |
||
206 | * @inheritDoc |
||
207 | */ |
||
208 | View Code Duplication | public function updateEntry($tableName, $id, array $data) |
|
216 | |||
217 | /** |
||
218 | * @inheritDoc |
||
219 | */ |
||
220 | public function deleteEntry($tableName, $ids) |
||
233 | |||
234 | /** |
||
235 | * @inheritDoc |
||
236 | */ |
||
237 | public function createUser(array $data) |
||
241 | |||
242 | /** |
||
243 | * @inheritDoc |
||
244 | */ |
||
245 | public function updateUser($id, array $data) |
||
249 | |||
250 | /** |
||
251 | * @inheritDoc |
||
252 | */ |
||
253 | public function deleteUser($ids) |
||
257 | |||
258 | /** |
||
259 | * @inheritDoc |
||
260 | */ |
||
261 | public function createFile(array $data) |
||
265 | |||
266 | /** |
||
267 | * @inheritDoc |
||
268 | */ |
||
269 | public function updateFile($id, array $data) |
||
273 | |||
274 | /** |
||
275 | * @inheritDoc |
||
276 | */ |
||
277 | public function deleteFile($ids) |
||
281 | |||
282 | /** |
||
283 | * @inheritdoc |
||
284 | */ |
||
285 | public function createActivity($data) |
||
289 | |||
290 | /** |
||
291 | * Get a table gateway for the given table name |
||
292 | * |
||
293 | * @param $tableName |
||
294 | * |
||
295 | * @return RelationalTableGateway |
||
296 | */ |
||
297 | protected function getTableGateway($tableName) |
||
306 | } |
||
307 |