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 |
||
12 | class SearchScope extends BaseScope |
||
13 | { |
||
14 | /** |
||
15 | * valid db conditions. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $acceptedConditions; |
||
20 | |||
21 | /** |
||
22 | * default db condition when not set. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $defaultCondition; |
||
27 | |||
28 | /** |
||
29 | * force where query symbol. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $forceWhereSymbol; |
||
34 | |||
35 | /** |
||
36 | * searchable fields. |
||
37 | * |
||
38 | * @var |
||
39 | */ |
||
40 | protected $validFields; |
||
41 | |||
42 | /** |
||
43 | * model table. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $modelTableName; |
||
48 | |||
49 | /** |
||
50 | * @var Model |
||
51 | */ |
||
52 | protected $model; |
||
53 | |||
54 | /** |
||
55 | * @param Builder $builder |
||
56 | * @param Model $model |
||
57 | * |
||
58 | * @return Builder |
||
59 | */ |
||
60 | public function apply(Builder $builder, Model $model) |
||
72 | |||
73 | /** |
||
74 | * @param Builder $builder |
||
75 | * @param Searchable $model |
||
76 | * |
||
77 | * @return $this|Builder |
||
78 | */ |
||
79 | protected function handle(Builder $builder, Searchable $model) |
||
116 | |||
117 | /** |
||
118 | * format fields from query. |
||
119 | * |
||
120 | * @param mixed $query |
||
121 | * |
||
122 | * @return array [] |
||
123 | */ |
||
124 | protected function parseQuery($query) |
||
143 | |||
144 | /** |
||
145 | * parse condition symbol and determine if force where is needed. |
||
146 | * |
||
147 | * @param $value |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | protected function parseCondition($value) |
||
175 | |||
176 | protected function mendSpecificFields($parameters) |
||
186 | |||
187 | protected function formatWhereHasClause(Builder $query, $fieldName, $fieldQuery, $force = false) |
||
211 | |||
212 | /** |
||
213 | * parse force where symbol. |
||
214 | * |
||
215 | * @param Builder $query |
||
216 | * @param string $fieldName |
||
217 | * @param arry $fieldQuery |
||
218 | * @param bool $force |
||
219 | * |
||
220 | * @return Builder |
||
221 | */ |
||
222 | protected function formatWhereClause(Builder $query, $fieldName, $fieldQuery, $force = false) |
||
237 | } |
||
238 |
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..