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 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function query() |
||
124 | 11 | ||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | View Code Duplication | public function statement($query, $bindings = []) |
|
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | View Code Duplication | public function affectingStatement($query, $bindings = []) |
|
177 | |||
178 | /** |
||
179 | * Get Arango.DB |
||
180 | * |
||
181 | * @return mixed |
||
182 | 11 | * |
|
183 | * @author Donii Sergii <[email protected]> |
||
184 | 11 | */ |
|
185 | public function getArangoDB() |
||
189 | |||
190 | /** |
||
191 | * Get Arango.DB client |
||
192 | * |
||
193 | * @return \ArangoDBClient\Connection |
||
194 | 11 | * |
|
195 | * @author Donii Sergii <[email protected]> |
||
196 | 11 | */ |
|
197 | public function getArangoClient() |
||
201 | |||
202 | /** |
||
203 | * Create new arango.db connection. |
||
204 | * |
||
205 | * @param array $config Config |
||
206 | 11 | * |
|
207 | * @return ArangoDBConnection |
||
208 | 11 | * |
|
209 | * @throws \ArangoDBClient\Exception |
||
210 | * |
||
211 | * @author Donii Sergii <[email protected]> |
||
212 | */ |
||
213 | public function createConnection(array $config = []) |
||
221 | |||
222 | /** |
||
223 | * Get database name. |
||
224 | * |
||
225 | * @return string |
||
226 | * |
||
227 | * @author Donii Sergii <[email protected]> |
||
228 | */ |
||
229 | public function getDatabaseName() |
||
235 | 11 | ||
236 | 11 | /** |
|
237 | * Get arango.db endpoint. |
||
238 | * |
||
239 | 11 | * @return string |
|
240 | * |
||
241 | * @author Donii Sergii <[email protected]> |
||
242 | */ |
||
243 | public function getEndPoint() |
||
247 | |||
248 | /** |
||
249 | 11 | * Get auth type |
|
250 | * |
||
251 | * @return string |
||
252 | * |
||
253 | 11 | * @author Donii Sergii <[email protected]> |
|
254 | */ |
||
255 | 11 | public function getAuthType() |
|
259 | 11 | ||
260 | /** |
||
261 | 11 | * Get auth type |
|
262 | * |
||
263 | 11 | * @return string |
|
264 | * |
||
265 | 11 | * @author Donii Sergii <[email protected]> |
|
266 | */ |
||
267 | 11 | public function getAuthUser() |
|
271 | 11 | ||
272 | /** |
||
273 | * Get auth type |
||
274 | * |
||
275 | * @return string |
||
276 | * |
||
277 | * @author Donii Sergii <[email protected]> |
||
278 | */ |
||
279 | public function getAuthPassword() |
||
283 | |||
284 | /** |
||
285 | * Get connection option |
||
286 | * |
||
287 | * @return string |
||
288 | * |
||
289 | * @author Donii Sergii <[email protected]> |
||
290 | */ |
||
291 | public function getConnectionOption() |
||
295 | |||
296 | /** |
||
297 | * Get timeout option |
||
298 | * |
||
299 | * @return int |
||
300 | * |
||
301 | * @author Donii Sergii <[email protected]> |
||
302 | */ |
||
303 | public function getTimeout() |
||
307 | |||
308 | /** |
||
309 | * Get reconnect option |
||
310 | * |
||
311 | * @return bool |
||
312 | * |
||
313 | * @author Donii Sergii <[email protected]> |
||
314 | */ |
||
315 | public function getReconnect() |
||
319 | |||
320 | /** |
||
321 | * Get create option |
||
322 | * |
||
323 | * @return mixed |
||
324 | * |
||
325 | * @author Donii Sergii <[email protected]> |
||
326 | */ |
||
327 | public function getCreate() |
||
331 | |||
332 | /** |
||
333 | * Get update policy option |
||
334 | * |
||
335 | * @return string |
||
336 | * |
||
337 | * @author Donii Sergii <[email protected]> |
||
338 | */ |
||
339 | public function getUpdatePolicy() |
||
343 | |||
344 | public function getDefaultQueryGrammar() |
||
348 | |||
349 | public function getDefaultPostProcessor() |
||
353 | |||
354 | protected function prepareBindingsInQuery($query) |
||
367 | |||
368 | /** |
||
369 | * Reconnect to the database if a PDO connection is missing. |
||
370 | * |
||
371 | * @throws \ArangoDBClient\Exception |
||
372 | * @return void |
||
373 | */ |
||
374 | protected function reconnectIfMissingConnection() |
||
380 | |||
381 | /** |
||
382 | * Get option value |
||
383 | * |
||
384 | * @param string $optionName |
||
385 | * @param mixed $default |
||
386 | * |
||
387 | * @return mixed |
||
388 | * |
||
389 | * @author Donii Sergii <[email protected]> |
||
390 | */ |
||
391 | private function getOption($optionName, $default) |
||
399 | |||
400 | /** |
||
401 | * Get main connection option |
||
402 | * |
||
403 | * @return array |
||
404 | * |
||
405 | * @author Donii Sergii <[email protected]> |
||
406 | */ |
||
407 | private function getMainConnectionOption() |
||
432 | } |
||
433 |