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 |
||
27 | class Connection extends IlluminateConnection |
||
28 | { |
||
29 | /** |
||
30 | * Arango.DB Query Builder |
||
31 | * |
||
32 | * @var |
||
33 | * |
||
34 | * @author Donii Sergii <[email protected]> |
||
35 | */ |
||
36 | protected $db; |
||
37 | |||
38 | protected $database = '_system'; |
||
39 | |||
40 | /** |
||
41 | * Arango.DB connection |
||
42 | * |
||
43 | * @var \ArangoDBClient\Connection |
||
44 | * |
||
45 | * @author Donii Sergii <[email protected]> |
||
46 | */ |
||
47 | protected $arangoConnection; |
||
48 | |||
49 | /** |
||
50 | 11 | * Connection constructor. |
|
51 | * |
||
52 | 11 | * @param array $config Connection options |
|
53 | * |
||
54 | 11 | * @throws Exception |
|
55 | * |
||
56 | 11 | * @author Donii Sergii <[email protected]> |
|
57 | 11 | */ |
|
58 | public function __construct(array $config = []) |
||
73 | |||
74 | /** |
||
75 | * Send AQL request to ArangoDB and return response with flat array |
||
76 | * |
||
77 | * @param string $query |
||
78 | 1 | * @param array $bindings |
|
79 | * @param bool $useReadPdo |
||
80 | 1 | * @return mixed |
|
81 | */ |
||
82 | public function select($query, $bindings = [], $useReadPdo = true) |
||
118 | /** |
||
119 | * @inheritdoc |
||
120 | */ |
||
121 | public function query() |
||
127 | |||
128 | /** |
||
129 | * @inheritdoc |
||
130 | */ |
||
131 | View Code Duplication | public function statement($query, $bindings = []) |
|
155 | |||
156 | /** |
||
157 | * @inheritdoc |
||
158 | 11 | */ |
|
159 | View Code Duplication | public function affectingStatement($query, $bindings = []) |
|
180 | |||
181 | /** |
||
182 | 11 | * Get Arango.DB |
|
183 | * |
||
184 | 11 | * @return mixed |
|
185 | * |
||
186 | * @author Donii Sergii <[email protected]> |
||
187 | */ |
||
188 | public function getArangoDB() |
||
192 | |||
193 | /** |
||
194 | 11 | * Get Arango.DB client |
|
195 | * |
||
196 | 11 | * @return \ArangoDBClient\Connection |
|
197 | * |
||
198 | * @author Donii Sergii <[email protected]> |
||
199 | */ |
||
200 | public function getArangoClient() |
||
204 | |||
205 | /** |
||
206 | 11 | * Create new arango.db connection. |
|
207 | * |
||
208 | 11 | * @param array $config Config |
|
209 | * |
||
210 | * @return ArangoDBConnection |
||
211 | * |
||
212 | * @throws \ArangoDBClient\Exception |
||
213 | * |
||
214 | * @author Donii Sergii <[email protected]> |
||
215 | */ |
||
216 | public function createConnection(array $config = []) |
||
224 | |||
225 | /** |
||
226 | * Get database name. |
||
227 | * |
||
228 | * @return string |
||
229 | * |
||
230 | * @author Donii Sergii <[email protected]> |
||
231 | */ |
||
232 | public function getDatabaseName() |
||
238 | |||
239 | 11 | /** |
|
240 | * Get arango.db endpoint. |
||
241 | * |
||
242 | * @return string |
||
243 | * |
||
244 | * @author Donii Sergii <[email protected]> |
||
245 | */ |
||
246 | public function getEndPoint() |
||
250 | |||
251 | /** |
||
252 | * Get auth type |
||
253 | 11 | * |
|
254 | * @return string |
||
255 | 11 | * |
|
256 | * @author Donii Sergii <[email protected]> |
||
257 | 11 | */ |
|
258 | public function getAuthType() |
||
262 | |||
263 | 11 | /** |
|
264 | * Get auth type |
||
265 | 11 | * |
|
266 | * @return string |
||
267 | 11 | * |
|
268 | * @author Donii Sergii <[email protected]> |
||
269 | 11 | */ |
|
270 | public function getAuthUser() |
||
274 | |||
275 | /** |
||
276 | * Get auth type |
||
277 | * |
||
278 | * @return string |
||
279 | * |
||
280 | * @author Donii Sergii <[email protected]> |
||
281 | */ |
||
282 | public function getAuthPassword() |
||
286 | |||
287 | /** |
||
288 | * Get connection option |
||
289 | * |
||
290 | * @return string |
||
291 | * |
||
292 | * @author Donii Sergii <[email protected]> |
||
293 | */ |
||
294 | public function getConnectionOption() |
||
298 | |||
299 | /** |
||
300 | * Get timeout option |
||
301 | * |
||
302 | * @return int |
||
303 | * |
||
304 | * @author Donii Sergii <[email protected]> |
||
305 | */ |
||
306 | public function getTimeout() |
||
310 | |||
311 | /** |
||
312 | * Get reconnect option |
||
313 | * |
||
314 | * @return bool |
||
315 | * |
||
316 | * @author Donii Sergii <[email protected]> |
||
317 | */ |
||
318 | public function getReconnect() |
||
322 | |||
323 | /** |
||
324 | * Get create option |
||
325 | * |
||
326 | * @return mixed |
||
327 | * |
||
328 | * @author Donii Sergii <[email protected]> |
||
329 | */ |
||
330 | public function getCreate() |
||
334 | |||
335 | /** |
||
336 | * Get update policy option |
||
337 | * |
||
338 | * @return string |
||
339 | * |
||
340 | * @author Donii Sergii <[email protected]> |
||
341 | */ |
||
342 | public function getUpdatePolicy() |
||
346 | |||
347 | public function getDefaultQueryGrammar() |
||
351 | |||
352 | public function getDefaultPostProcessor() |
||
356 | |||
357 | protected function prepareBindingsInQuery($query){ |
||
369 | |||
370 | /** |
||
371 | * Reconnect to the database if a PDO connection is missing. |
||
372 | * |
||
373 | * @throws \ArangoDBClient\Exception |
||
374 | * @return void |
||
375 | */ |
||
376 | protected function reconnectIfMissingConnection() |
||
382 | |||
383 | /** |
||
384 | * Get option value |
||
385 | * |
||
386 | * @param string $optionName |
||
387 | * @param mixed $default |
||
388 | * |
||
389 | * @return mixed |
||
390 | * |
||
391 | * @author Donii Sergii <[email protected]> |
||
392 | */ |
||
393 | private function getOption($optionName, $default) |
||
401 | |||
402 | /** |
||
403 | * Get main connection option |
||
404 | * |
||
405 | * @return array |
||
406 | * |
||
407 | * @author Donii Sergii <[email protected]> |
||
408 | */ |
||
409 | private function getMainConnectionOption() |
||
434 | } |
||
435 |