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) |
|
211 | |||
212 | /** |
||
213 | * @inheritDoc |
||
214 | */ |
||
215 | View Code Duplication | public function updateEntry($tableName, $id, array $data) |
|
230 | |||
231 | /** |
||
232 | * @inheritDoc |
||
233 | */ |
||
234 | public function deleteEntry($tableName, $ids) |
||
247 | |||
248 | /** |
||
249 | * @inheritDoc |
||
250 | */ |
||
251 | public function createUser(array $data) |
||
255 | |||
256 | /** |
||
257 | * @inheritDoc |
||
258 | */ |
||
259 | public function updateUser($id, array $data) |
||
263 | |||
264 | /** |
||
265 | * @inheritDoc |
||
266 | */ |
||
267 | public function deleteUser($ids) |
||
271 | |||
272 | /** |
||
273 | * @inheritDoc |
||
274 | */ |
||
275 | public function createFile(File $file) |
||
281 | |||
282 | /** |
||
283 | * @inheritDoc |
||
284 | */ |
||
285 | public function updateFile($id, array $data) |
||
289 | |||
290 | /** |
||
291 | * @inheritDoc |
||
292 | */ |
||
293 | public function deleteFile($ids) |
||
297 | |||
298 | /** |
||
299 | * Get a table gateway for the given table name |
||
300 | * |
||
301 | * @param $tableName |
||
302 | * |
||
303 | * @return RelationalTableGateway |
||
304 | */ |
||
305 | protected function getTableGateway($tableName) |
||
314 | } |
||
315 |