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 Connection extends IlluminateConnection |
||
27 | { |
||
28 | /** |
||
29 | * Arango.DB Query Builder |
||
30 | * |
||
31 | * @var |
||
32 | * |
||
33 | * @author Donii Sergii <[email protected]> |
||
34 | */ |
||
35 | protected $db; |
||
36 | |||
37 | protected $database = '_system'; |
||
38 | |||
39 | /** |
||
40 | * Arango.DB connection |
||
41 | * |
||
42 | * @var \ArangoDBClient\Connection |
||
43 | * |
||
44 | * @author Donii Sergii <[email protected]> |
||
45 | */ |
||
46 | protected $arangoConnection; |
||
47 | |||
48 | /** |
||
49 | * Connection constructor. |
||
50 | 11 | * |
|
51 | * @param array $config Connection options |
||
52 | 11 | * |
|
53 | * @throws ArangoException |
||
54 | 11 | * |
|
55 | * @author Donii Sergii <[email protected]> |
||
56 | 11 | */ |
|
57 | 11 | public function __construct(array $config = []) |
|
72 | |||
73 | /** |
||
74 | * Send AQL request to ArangoDB and return response with flat array |
||
75 | * |
||
76 | * @param string $query |
||
77 | * @param array $bindings |
||
78 | 1 | * @param bool $useReadPdo |
|
79 | * @return mixed |
||
80 | 1 | */ |
|
81 | public function select($query, $bindings = [], $useReadPdo = true) |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function query() |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | View Code Duplication | public function statement($query, $bindings = []) |
|
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | View Code Duplication | public function affectingStatement($query, $bindings = []) |
|
178 | |||
179 | /** |
||
180 | * Get Arango.DB |
||
181 | * |
||
182 | 11 | * @return mixed |
|
183 | * |
||
184 | 11 | * @author Donii Sergii <[email protected]> |
|
185 | */ |
||
186 | public function getArangoDB() |
||
190 | |||
191 | /** |
||
192 | * Get Arango.DB client |
||
193 | * |
||
194 | 11 | * @return \ArangoDBClient\Connection |
|
195 | * |
||
196 | 11 | * @author Donii Sergii <[email protected]> |
|
197 | */ |
||
198 | public function getArangoClient() |
||
202 | |||
203 | /** |
||
204 | * Create new arango.db connection. |
||
205 | * |
||
206 | 11 | * @param array $config Config |
|
207 | * |
||
208 | 11 | * @return ArangoDBConnection |
|
209 | * |
||
210 | * @throws \ArangoDBClient\Exception |
||
211 | * |
||
212 | * @author Donii Sergii <[email protected]> |
||
213 | */ |
||
214 | public function createConnection(array $config = []) |
||
222 | |||
223 | /** |
||
224 | * Get database name. |
||
225 | * |
||
226 | * @return string |
||
227 | * |
||
228 | * @author Donii Sergii <[email protected]> |
||
229 | */ |
||
230 | public function getDatabaseName() |
||
236 | 11 | ||
237 | /** |
||
238 | * Get arango.db endpoint. |
||
239 | 11 | * |
|
240 | * @return string |
||
241 | * |
||
242 | * @author Donii Sergii <[email protected]> |
||
243 | */ |
||
244 | public function getEndPoint() |
||
248 | |||
249 | 11 | /** |
|
250 | * Get auth type |
||
251 | * |
||
252 | * @return string |
||
253 | 11 | * |
|
254 | * @author Donii Sergii <[email protected]> |
||
255 | 11 | */ |
|
256 | public function getAuthType() |
||
260 | |||
261 | 11 | /** |
|
262 | * Get auth type |
||
263 | 11 | * |
|
264 | * @return string |
||
265 | 11 | * |
|
266 | * @author Donii Sergii <[email protected]> |
||
267 | 11 | */ |
|
268 | public function getAuthUser() |
||
272 | |||
273 | /** |
||
274 | * Get auth type |
||
275 | * |
||
276 | * @return string |
||
277 | * |
||
278 | * @author Donii Sergii <[email protected]> |
||
279 | */ |
||
280 | public function getAuthPassword() |
||
284 | |||
285 | /** |
||
286 | * Get connection option |
||
287 | * |
||
288 | * @return string |
||
289 | * |
||
290 | * @author Donii Sergii <[email protected]> |
||
291 | */ |
||
292 | public function getConnectionOption() |
||
296 | |||
297 | /** |
||
298 | * Get timeout option |
||
299 | * |
||
300 | * @return int |
||
301 | * |
||
302 | * @author Donii Sergii <[email protected]> |
||
303 | */ |
||
304 | public function getTimeout() |
||
308 | |||
309 | /** |
||
310 | * Get reconnect option |
||
311 | * |
||
312 | * @return bool |
||
313 | * |
||
314 | * @author Donii Sergii <[email protected]> |
||
315 | */ |
||
316 | public function getReconnect() |
||
320 | |||
321 | /** |
||
322 | * Get create option |
||
323 | * |
||
324 | * @return mixed |
||
325 | * |
||
326 | * @author Donii Sergii <[email protected]> |
||
327 | */ |
||
328 | public function getCreate() |
||
332 | |||
333 | /** |
||
334 | * Get update policy option |
||
335 | * |
||
336 | * @return string |
||
337 | * |
||
338 | * @author Donii Sergii <[email protected]> |
||
339 | */ |
||
340 | public function getUpdatePolicy() |
||
344 | |||
345 | public function getDefaultQueryGrammar() |
||
349 | |||
350 | public function getDefaultPostProcessor() |
||
354 | |||
355 | protected function prepareBindingsInQuery($query) |
||
368 | |||
369 | /** |
||
370 | * Reconnect to the database if a PDO connection is missing. |
||
371 | * |
||
372 | * @throws \ArangoDBClient\Exception |
||
373 | * @return void |
||
374 | */ |
||
375 | protected function reconnectIfMissingConnection() |
||
381 | |||
382 | /** |
||
383 | * Get option value |
||
384 | * |
||
385 | * @param string $optionName |
||
386 | * @param mixed $default |
||
387 | * |
||
388 | * @return mixed |
||
389 | * |
||
390 | * @author Donii Sergii <[email protected]> |
||
391 | */ |
||
392 | private function getOption($optionName, $default) |
||
400 | |||
401 | /** |
||
402 | * Get main connection option |
||
403 | * |
||
404 | * @return array |
||
405 | * |
||
406 | * @author Donii Sergii <[email protected]> |
||
407 | */ |
||
408 | private function getMainConnectionOption() |
||
433 | } |
||
434 |