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 |
||
18 | class Builder extends \Illuminate\Database\Query\Builder |
||
19 | { |
||
20 | /** |
||
21 | * The database connection instance. |
||
22 | * |
||
23 | * @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection |
||
24 | */ |
||
25 | protected $connection; |
||
26 | |||
27 | /** |
||
28 | * The database query grammar instance. |
||
29 | * |
||
30 | * @var \Ytake\LaravelCouchbase\Query\Grammar |
||
31 | */ |
||
32 | protected $grammar; |
||
33 | |||
34 | /** @var string use-keys-clause */ |
||
35 | public $key; |
||
36 | |||
37 | /** @var string[] returning-clause */ |
||
38 | public $returning = ['*']; |
||
39 | |||
40 | /** |
||
41 | * @param $key |
||
42 | * |
||
43 | * @return $this |
||
44 | */ |
||
45 | 6 | public function key($key) |
|
51 | |||
52 | /** |
||
53 | * @param array $column |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | 3 | public function returning(array $column = ['*']) |
|
63 | |||
64 | /** |
||
65 | * Insert a new record into the database. |
||
66 | * |
||
67 | * @param array $values |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 4 | View Code Duplication | public function insert(array $values) |
88 | |||
89 | /** |
||
90 | * supported N1QL upsert query. |
||
91 | * |
||
92 | * @param array $values |
||
93 | * |
||
94 | * @return bool|mixed |
||
95 | */ |
||
96 | 1 | View Code Duplication | public function upsert(array $values) |
113 | |||
114 | /** |
||
115 | * @param string|int|array $values |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 5 | protected function detectValues($values) |
|
132 | } |
||
133 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.