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 |
||
8 | class Select extends SelectOrUnionAll |
||
9 | { |
||
10 | /** |
||
11 | * @var ConditionGroup[] |
||
12 | */ |
||
13 | protected $where; |
||
14 | |||
15 | /** |
||
16 | * @var Order[] |
||
17 | */ |
||
18 | protected $orders; |
||
19 | |||
20 | /** |
||
21 | * @var Limit |
||
22 | */ |
||
23 | protected $limit; |
||
24 | |||
25 | /** |
||
26 | * Select constructor. |
||
27 | * |
||
28 | * @param ConditionGroup[] $where |
||
29 | * @param Order[] $orders |
||
30 | * @param Limit $limit |
||
31 | */ |
||
32 | 17 | public function __construct(array $where, array $orders, Limit $limit) |
|
38 | |||
39 | /** |
||
40 | * @param Order[] ...$orders |
||
41 | * @return Order[] |
||
42 | */ |
||
43 | 17 | protected static function validate(Order ...$orders) |
|
47 | |||
48 | /** |
||
49 | * @return ConditionGroup[] |
||
50 | */ |
||
51 | 17 | public function where() |
|
55 | |||
56 | /** |
||
57 | * @return Order[] |
||
58 | */ |
||
59 | 17 | public function orders() |
|
63 | |||
64 | /** |
||
65 | * @return Limit |
||
66 | */ |
||
67 | 17 | public function limit() |
|
71 | |||
72 | /** |
||
73 | * @return static |
||
74 | */ |
||
75 | 10 | public function inverse() |
|
87 | |||
88 | /** |
||
89 | * Clone Select. |
||
90 | */ |
||
91 | View Code Duplication | public function __clone() |
|
101 | |||
102 | /** |
||
103 | * Retrieve an external iterator. |
||
104 | * |
||
105 | * @return \ArrayIterator|Select[] |
||
106 | */ |
||
107 | public function getIterator() |
||
111 | } |
||
112 |
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..