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 |
||
24 | class Grammar extends IlluminateGrammar |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 7 | protected function wrapValue($value) |
|
37 | |||
38 | /** |
||
39 | * @param $value |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | 6 | protected function wrapKey($value) |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | * |
||
55 | * notice: supported set query only |
||
56 | */ |
||
57 | 1 | public function compileUpdate(Builder $query, $values) |
|
58 | { |
||
59 | // keyspace-ref: |
||
60 | 1 | $table = $this->wrapTable($query->from); |
|
61 | // use-keys-clause: |
||
62 | 1 | $keyClause = $this->wrapKey($query->key); |
|
|
|||
63 | // returning-clause |
||
64 | 1 | $returning = implode(', ', $query->returning); |
|
65 | |||
66 | 1 | $columns = []; |
|
67 | |||
68 | 1 | foreach ($values as $key => $value) { |
|
69 | 1 | $columns[] = $this->wrap($key) . ' = ' . $this->parameter($value); |
|
70 | 1 | } |
|
71 | |||
72 | 1 | $columns = implode(', ', $columns); |
|
73 | |||
74 | 1 | $joins = ''; |
|
75 | 1 | if (isset($query->joins)) { |
|
76 | $joins = ' ' . $this->compileJoins($query, $query->joins); |
||
77 | } |
||
78 | 1 | $where = $this->compileWheres($query); |
|
79 | |||
80 | 1 | return trim("update {$table} USE KEYS {$keyClause} {$joins} set $columns $where RETURNING {$returning}"); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 4 | View Code Duplication | public function compileInsert(Builder $query, array $values) |
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | * |
||
112 | * @see http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/delete.html |
||
113 | */ |
||
114 | 7 | public function compileDelete(Builder $query) |
|
130 | |||
131 | /** |
||
132 | * @param QueryBuilder $query |
||
133 | * @param array $values |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | View Code Duplication | public function compileUpsert(QueryBuilder $query, array $values) |
159 | } |
||
160 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.