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 | ||
| 19 | class NextrasDataSource extends FilterableDataSource implements IDataSource | ||
| 20 | { | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @var DbalCollection | ||
| 24 | */ | ||
| 25 | protected $data_source; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * @var array | ||
| 29 | */ | ||
| 30 | protected $data = []; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * @var array | ||
| 34 | */ | ||
| 35 | protected $aggregations = []; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * @var string | ||
| 39 | */ | ||
| 40 | protected $primary_key; | ||
| 41 | |||
| 42 | |||
| 43 | /** | ||
| 44 | * @param ICollection $data_source | ||
| 45 | * @param string $primary_key | ||
| 46 | */ | ||
| 47 | public function __construct(ICollection $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 | * Get the data | ||
| 70 | * @return array | ||
| 71 | */ | ||
| 72 | public function getData() | ||
| 79 | |||
| 80 | |||
| 81 | /** | ||
| 82 | * Filter data - get one row | ||
| 83 | * @param array $condition | ||
| 84 | * @return static | ||
| 85 | */ | ||
| 86 | public function filterOne(array $condition) | ||
| 96 | |||
| 97 | |||
| 98 | /** | ||
| 99 | * Filter by date | ||
| 100 | * @param Filter\FilterDate $filter | ||
| 101 | * @return static | ||
| 102 | */ | ||
| 103 | public function applyFilterDate(Filter\FilterDate $filter) | ||
| 117 | |||
| 118 | |||
| 119 | /** | ||
| 120 | * Filter by date range | ||
| 121 | * @param Filter\FilterDateRange $filter | ||
| 122 | * @return void | ||
| 123 | */ | ||
| 124 | public function applyFilterDateRange(Filter\FilterDateRange $filter) | ||
| 146 | |||
| 147 | |||
| 148 | /** | ||
| 149 | * Filter by range | ||
| 150 | * @param Filter\FilterRange $filter | ||
| 151 | * @return void | ||
| 152 | */ | ||
| 153 | public function applyFilterRange(Filter\FilterRange $filter) | ||
| 174 | |||
| 175 | |||
| 176 | /** | ||
| 177 | * Filter by keyword | ||
| 178 | * @param Filter\FilterText $filter | ||
| 179 | * @return void | ||
| 180 | */ | ||
| 181 | public function applyFilterText(Filter\FilterText $filter) | ||
| 214 | |||
| 215 | |||
| 216 | /** | ||
| 217 | * Filter by multi select value | ||
| 218 | * @param Filter\FilterMultiSelect $filter | ||
| 219 | * @return void | ||
| 220 | */ | ||
| 221 | public function applyFilterMultiSelect(Filter\FilterMultiSelect $filter) | ||
| 239 | |||
| 240 | |||
| 241 | /** | ||
| 242 | * Filter by select value | ||
| 243 | * @param Filter\FilterSelect $filter | ||
| 244 | * @return void | ||
| 245 | */ | ||
| 246 | public function applyFilterSelect(Filter\FilterSelect $filter) | ||
| 250 | |||
| 251 | |||
| 252 | /** | ||
| 253 | * Apply limit and offset on data | ||
| 254 | * @param int $offset | ||
| 255 | * @param int $limit | ||
| 256 | * @return static | ||
| 257 | */ | ||
| 258 | public function limit($offset, $limit) | ||
| 264 | |||
| 265 | |||
| 266 | /** | ||
| 267 | * Sort data | ||
| 268 | * @param Sorting $sorting | ||
| 269 | * @return static | ||
| 270 | */ | ||
| 271 | public function sort(Sorting $sorting) | ||
| 302 | |||
| 303 | /** | ||
| 304 | * Adjust column from DataGrid 'foreignKey.column' to Nextras 'this->foreignKey->column' | ||
| 305 | * @param string $column | ||
| 306 | * @return string | ||
| 307 | */ | ||
| 308 | private function prepareColumn($column) | ||
| 315 | |||
| 316 | /** | ||
| 317 | * @param string $aggregation_type | ||
| 318 | * @param string $column | ||
| 319 | * @return mixed | ||
| 320 | */ | ||
| 321 | public function addAggregationColumn($aggregation_type, $column) | ||
| 325 | |||
| 326 | /** | ||
| 327 | * get aggregation row | ||
| 328 | * @return array | ||
| 329 | */ | ||
| 330 | public function getAggregationData() | ||
| 353 | } | ||
| 354 | 
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.