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 SelectQuery extends AbstractQuery |
||
27 | { |
||
28 | use Executable, Fetchable, From, Limit, OrderBy, Where; |
||
29 | |||
30 | /** |
||
31 | * @var SelectStatement |
||
32 | */ |
||
33 | protected $select; |
||
34 | |||
35 | /** |
||
36 | * @var WhereStatement |
||
37 | */ |
||
38 | protected $having; |
||
39 | |||
40 | /** |
||
41 | * @var OrderStatement |
||
42 | */ |
||
43 | protected $groupBy; |
||
44 | |||
45 | /** |
||
46 | * @var UnionStatement |
||
47 | */ |
||
48 | protected $union; |
||
49 | |||
50 | public function __construct() |
||
61 | |||
62 | /** |
||
63 | * Sets the fields to be selected for the query. |
||
64 | * |
||
65 | * @param array|string $fields fields |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function select($fields) |
||
75 | |||
76 | /** |
||
77 | * Adds a join to the query. |
||
78 | * |
||
79 | * @param string $table table name |
||
80 | * @param string $on ON condition |
||
81 | * @param string $using USING columns |
||
82 | * @param string $type optional join type if not JOIN |
||
83 | * |
||
84 | * @return self |
||
85 | */ |
||
86 | public function join($table, $on = null, $using = null, $type = 'JOIN') |
||
92 | |||
93 | /** |
||
94 | * Sets the group by fields for the query. |
||
95 | * |
||
96 | * @param string|array $fields |
||
97 | * @param string $direction |
||
98 | * |
||
99 | * @return self |
||
100 | */ |
||
101 | public function groupBy($fields, $direction = false) |
||
107 | |||
108 | /** |
||
109 | * Sets the having conditions for the query. |
||
110 | * |
||
111 | * @param array|string $field |
||
112 | * @param string|bool $condition condition value (optional) |
||
113 | * @param string $operator operator (optional) |
||
114 | * |
||
115 | * @return self |
||
116 | */ |
||
117 | View Code Duplication | public function having($field, $condition = false, $operator = '=') |
|
127 | |||
128 | /** |
||
129 | * Unions another select query with this query. |
||
130 | * |
||
131 | * @param SelectQuery $query |
||
132 | * @param string $type optional union type |
||
133 | * |
||
134 | * @return self |
||
135 | */ |
||
136 | public function union(SelectQuery $query, $type = '') |
||
142 | |||
143 | /** |
||
144 | * Gets the select statement for the query. |
||
145 | * |
||
146 | * @return SelectStatement |
||
147 | */ |
||
148 | public function getSelect() |
||
152 | |||
153 | /** |
||
154 | * Gets the group by statement for the query. |
||
155 | * |
||
156 | * @return GroupByStatement |
||
157 | */ |
||
158 | public function getGroupBy() |
||
162 | |||
163 | /** |
||
164 | * Gets the having statement for the query. |
||
165 | * |
||
166 | * @return WhereStatement |
||
167 | */ |
||
168 | public function getHaving() |
||
172 | |||
173 | /** |
||
174 | * Gets the union statement for the query. |
||
175 | * |
||
176 | * @return UnionStatement |
||
177 | */ |
||
178 | public function getUnion() |
||
182 | |||
183 | /** |
||
184 | * Generates the raw SQL string for the query. |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function build() |
||
217 | |||
218 | public function __clone() |
||
229 | } |
||
230 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..