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 |
||
| 25 | class SelectQuery extends AbstractQuery |
||
| 26 | { |
||
| 27 | use Executable, Fetchable, Limit, OrderBy, Where; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var SelectStatement |
||
| 31 | */ |
||
| 32 | protected $select; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var FromStatement |
||
| 36 | */ |
||
| 37 | protected $from; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var WhereStatement |
||
| 41 | */ |
||
| 42 | protected $having; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var OrderStatement |
||
| 46 | */ |
||
| 47 | protected $groupBy; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var UnionStatement |
||
| 51 | */ |
||
| 52 | protected $union; |
||
| 53 | |||
| 54 | public function __construct() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Sets the fields to be selected for the query. |
||
| 68 | * |
||
| 69 | * @param array|string $fields fields |
||
| 70 | * |
||
| 71 | * @return self |
||
| 72 | */ |
||
| 73 | public function select($fields) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Sets the table for the query. |
||
| 82 | * |
||
| 83 | * @param string $table table name |
||
| 84 | * |
||
| 85 | * @return self |
||
| 86 | */ |
||
| 87 | public function from($table) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Adds a join to the query. |
||
| 96 | * |
||
| 97 | * @param string $table table name |
||
| 98 | * @param string $on ON condition |
||
| 99 | * @param string $using USING columns |
||
| 100 | * @param string $type optional join type if not JOIN |
||
| 101 | * |
||
| 102 | * @return self |
||
| 103 | */ |
||
| 104 | public function join($table, $on = null, $using = null, $type = 'JOIN') |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Sets the group by fields for the query. |
||
| 113 | * |
||
| 114 | * @param string|array $fields |
||
| 115 | * @param string $direction |
||
| 116 | * |
||
| 117 | * @return self |
||
| 118 | */ |
||
| 119 | public function groupBy($fields, $direction = false) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Sets the having conditions for the query. |
||
| 128 | * |
||
| 129 | * @param array|string $field |
||
| 130 | * @param string|bool $condition condition value (optional) |
||
| 131 | * @param string $operator operator (optional) |
||
| 132 | * |
||
| 133 | * @return self |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function having($field, $condition = false, $operator = '=') |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Unions another select query with this query. |
||
| 148 | * |
||
| 149 | * @param SelectQuery $query |
||
| 150 | * @param string $type optional union type |
||
| 151 | * |
||
| 152 | * @return self |
||
| 153 | */ |
||
| 154 | public function union(SelectQuery $query, $type = '') |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Gets the select statement for the query. |
||
| 163 | * |
||
| 164 | * @return SelectStatement |
||
| 165 | */ |
||
| 166 | public function getSelect() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Gets the from statement for the query. |
||
| 173 | * |
||
| 174 | * @return FromStatement |
||
| 175 | */ |
||
| 176 | public function getFrom() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Gets the group by statement for the query. |
||
| 183 | * |
||
| 184 | * @return GroupByStatement |
||
| 185 | */ |
||
| 186 | public function getGroupBy() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Gets the having statement for the query. |
||
| 193 | * |
||
| 194 | * @return WhereStatement |
||
| 195 | */ |
||
| 196 | public function getHaving() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Gets the union statement for the query. |
||
| 203 | * |
||
| 204 | * @return UnionStatement |
||
| 205 | */ |
||
| 206 | public function getUnion() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Generates the raw SQL string for the query. |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function build() |
||
| 245 | |||
| 246 | public function __clone() |
||
| 257 | } |
||
| 258 |
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..