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 DibiFluentDataSource extends FilterableDataSource implements IDataSource |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var Dibi\Fluent |
||
23 | */ |
||
24 | protected $data_source; |
||
25 | |||
26 | /** |
||
27 | * @var Dibi\Fluent |
||
28 | */ |
||
29 | protected $aggregation_data_source; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $data = []; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $primary_key; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $hasAggregationFunctions = FALSE; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @param Dibi\Fluent $data_source |
||
49 | * @param string $primary_key |
||
50 | */ |
||
51 | public function __construct(Dibi\Fluent $data_source, $primary_key) |
||
57 | |||
58 | |||
59 | /******************************************************************************** |
||
60 | * IDataSource implementation * |
||
61 | ********************************************************************************/ |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Get count of data |
||
66 | * @return int |
||
67 | */ |
||
68 | public function getCount() |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Get the data |
||
76 | * @return array |
||
77 | */ |
||
78 | public function getData() |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Filter data - get one row |
||
86 | * @param array $condition |
||
87 | * @return static |
||
88 | */ |
||
89 | public function filterOne(array $condition) |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Filter by date |
||
99 | * @param Filter\FilterDate $filter |
||
100 | * @return void |
||
101 | */ |
||
102 | View Code Duplication | public function applyFilterDate(Filter\FilterDate $filter) |
|
110 | |||
111 | |||
112 | /** |
||
113 | * Filter by date range |
||
114 | * @param Filter\FilterDateRange $filter |
||
115 | * @return void |
||
116 | */ |
||
117 | public function applyFilterDateRange(Filter\FilterDateRange $filter) |
||
138 | |||
139 | |||
140 | /** |
||
141 | * Filter by range |
||
142 | * @param Filter\FilterRange $filter |
||
143 | * @return void |
||
144 | */ |
||
145 | public function applyFilterRange(Filter\FilterRange $filter) |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Filter by keyword |
||
164 | * @param Filter\FilterText $filter |
||
165 | * @return void |
||
166 | */ |
||
167 | public function applyFilterText(Filter\FilterText $filter) |
||
208 | |||
209 | |||
210 | /** |
||
211 | * Filter by multi select value |
||
212 | * @param Filter\FilterMultiSelect $filter |
||
213 | * @return void |
||
214 | */ |
||
215 | public function applyFilterMultiSelect(Filter\FilterMultiSelect $filter) |
||
241 | |||
242 | |||
243 | /** |
||
244 | * Filter by select value |
||
245 | * @param Filter\FilterSelect $filter |
||
246 | * @return void |
||
247 | */ |
||
248 | public function applyFilterSelect(Filter\FilterSelect $filter) |
||
252 | |||
253 | |||
254 | /** |
||
255 | * Apply limit and offset on data |
||
256 | * @param int $offset |
||
257 | * @param int $limit |
||
258 | * @return static |
||
259 | */ |
||
260 | public function limit($offset, $limit) |
||
266 | |||
267 | |||
268 | /** |
||
269 | * Sort data |
||
270 | * @param Sorting $sorting |
||
271 | * @return static |
||
272 | */ |
||
273 | public function sort(Sorting $sorting) |
||
308 | |||
309 | /** |
||
310 | * @param string $aggregation_type |
||
311 | * @param string $column |
||
312 | */ |
||
313 | public function addAggregationColumn($aggregation_type, $column) |
||
317 | |||
318 | |||
319 | /** |
||
320 | * @return array|Dibi\Row|FALSE |
||
321 | */ |
||
322 | public function getAggregationData() |
||
330 | } |
||
331 |
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..