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 |
||
18 | class Query |
||
19 | { |
||
20 | /** |
||
21 | * @var Select|SelectOrUnionAll|UnionAll |
||
22 | */ |
||
23 | protected $selectOrUnionAll; |
||
24 | |||
25 | /** |
||
26 | * @var Order[] |
||
27 | */ |
||
28 | protected $orders; |
||
29 | |||
30 | /** |
||
31 | * @var Cursor |
||
32 | */ |
||
33 | protected $cursor; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $limit; |
||
39 | |||
40 | /** |
||
41 | * @var Direction |
||
42 | */ |
||
43 | protected $direction; |
||
44 | |||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | protected $exclusive; |
||
49 | |||
50 | /** |
||
51 | * @var bool |
||
52 | */ |
||
53 | protected $seekable; |
||
54 | |||
55 | /** |
||
56 | * @var mixed |
||
57 | */ |
||
58 | protected $builder; |
||
59 | |||
60 | /** |
||
61 | * @param string[][] $orders |
||
62 | * @param Cursor|int[]|string[] $cursor |
||
63 | * @param int $limit |
||
64 | * @param bool $backward |
||
65 | * @param bool $exclusive |
||
66 | * @param bool $seekable |
||
67 | * @param mixed $builder |
||
68 | * @return static |
||
69 | */ |
||
70 | 17 | public static function create(array $orders, $cursor, $limit, $backward, $exclusive, $seekable, $builder = null) |
|
86 | |||
87 | /** |
||
88 | * Query constructor. |
||
89 | * |
||
90 | * @param Select|SelectOrUnionAll|UnionAll $selectOrUnionAll |
||
91 | * @param Order[] $orders |
||
92 | * @param Cursor $cursor |
||
93 | * @param Limit $limit |
||
94 | * @param Direction $direction |
||
95 | * @param bool $exclusive |
||
96 | * @param bool $seekable |
||
97 | * @param mixed $builder |
||
98 | */ |
||
99 | 17 | public function __construct(SelectOrUnionAll $selectOrUnionAll, array $orders, Cursor $cursor, Limit $limit, Direction $direction, $exclusive, $seekable, $builder = null) |
|
120 | |||
121 | /** |
||
122 | * @return Select|SelectOrUnionAll|UnionAll |
||
123 | */ |
||
124 | 17 | public function selectOrUnionAll() |
|
128 | |||
129 | /** |
||
130 | * @return Order[] |
||
131 | */ |
||
132 | public function orders() |
||
136 | |||
137 | /** |
||
138 | * @return Cursor |
||
139 | */ |
||
140 | public function cursor() |
||
144 | |||
145 | /** |
||
146 | * @return int |
||
147 | */ |
||
148 | 2 | public function limit() |
|
152 | |||
153 | /** |
||
154 | * @return Direction |
||
155 | */ |
||
156 | 2 | public function direction() |
|
160 | |||
161 | /** |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function forward() |
||
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function backward() |
||
176 | |||
177 | /** |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function exclusive() |
||
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function inclusive() |
||
192 | |||
193 | /** |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function seekable() |
||
200 | |||
201 | /** |
||
202 | * @return bool |
||
203 | */ |
||
204 | public function unseekable() |
||
208 | |||
209 | /** |
||
210 | * @return mixed |
||
211 | */ |
||
212 | 2 | public function builder() |
|
216 | |||
217 | /** |
||
218 | * Clone Query. |
||
219 | */ |
||
220 | View Code Duplication | public function __clone() |
|
228 | } |
||
229 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.