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 DibiFluent | ||
| 23 | */ | ||
| 24 | protected $data_source; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * @var DibiFluent | ||
| 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 | /** | ||
| 43 | * @param DibiFluent $data_source | ||
| 44 | * @param string $primary_key | ||
| 45 | */ | ||
| 46 | public function __construct(\Dibi\Fluent $data_source, $primary_key) | ||
| 52 | |||
| 53 | |||
| 54 | /******************************************************************************** | ||
| 55 | * IDataSource implementation * | ||
| 56 | ********************************************************************************/ | ||
| 57 | |||
| 58 | |||
| 59 | /** | ||
| 60 | * Get count of data | ||
| 61 | * @return int | ||
| 62 | */ | ||
| 63 | public function getCount() | ||
| 67 | |||
| 68 | |||
| 69 | /** | ||
| 70 | * Get the data | ||
| 71 | * @return array | ||
| 72 | */ | ||
| 73 | public function getData() | ||
| 77 | |||
| 78 | |||
| 79 | /** | ||
| 80 | * Filter data - get one row | ||
| 81 | * @param array $condition | ||
| 82 | * @return static | ||
| 83 | */ | ||
| 84 | public function filterOne(array $condition) | ||
| 90 | |||
| 91 | |||
| 92 | /** | ||
| 93 | * Filter by date | ||
| 94 | * @param Filter\FilterDate $filter | ||
| 95 | * @return void | ||
| 96 | */ | ||
| 97 | View Code Duplication | public function applyFilterDate(Filter\FilterDate $filter) | |
| 105 | |||
| 106 | |||
| 107 | /** | ||
| 108 | * Filter by date range | ||
| 109 | * @param Filter\FilterDateRange $filter | ||
| 110 | * @return void | ||
| 111 | */ | ||
| 112 | View Code Duplication | public function applyFilterDateRange(Filter\FilterDateRange $filter) | |
| 133 | |||
| 134 | |||
| 135 | /** | ||
| 136 | * Filter by range | ||
| 137 | * @param Filter\FilterRange $filter | ||
| 138 | * @return void | ||
| 139 | */ | ||
| 140 | public function applyFilterRange(Filter\FilterRange $filter) | ||
| 155 | |||
| 156 | |||
| 157 | /** | ||
| 158 | * Filter by keyword | ||
| 159 | * @param Filter\FilterText $filter | ||
| 160 | * @return void | ||
| 161 | */ | ||
| 162 | public function applyFilterText(Filter\FilterText $filter) | ||
| 203 | |||
| 204 | |||
| 205 | /** | ||
| 206 | * Filter by multi select value | ||
| 207 | * @param Filter\FilterMultiSelect $filter | ||
| 208 | * @return void | ||
| 209 | */ | ||
| 210 | public function applyFilterMultiSelect(Filter\FilterMultiSelect $filter) | ||
| 236 | |||
| 237 | |||
| 238 | /** | ||
| 239 | * Filter by select value | ||
| 240 | * @param Filter\FilterSelect $filter | ||
| 241 | * @return void | ||
| 242 | */ | ||
| 243 | public function applyFilterSelect(Filter\FilterSelect $filter) | ||
| 247 | |||
| 248 | |||
| 249 | /** | ||
| 250 | * Apply limit and offset on data | ||
| 251 | * @param int $offset | ||
| 252 | * @param int $limit | ||
| 253 | * @return static | ||
| 254 | */ | ||
| 255 | public function limit($offset, $limit) | ||
| 261 | |||
| 262 | |||
| 263 | /** | ||
| 264 | * Sort data | ||
| 265 | * @param Sorting $sorting | ||
| 266 | * @return static | ||
| 267 | */ | ||
| 268 | public function sort(Sorting $sorting) | ||
| 303 | |||
| 304 | public function addAggregationColumn($aggregation_type, $column) | ||
| 308 | |||
| 309 | public function getAggregationData() | ||
| 314 | } | ||
| 315 | 
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..