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 string |
||
| 34 | */ |
||
| 35 | protected $primary_key; |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * @param ICollection $data_source |
||
| 40 | * @param string $primary_key |
||
| 41 | */ |
||
| 42 | public function __construct(ICollection $data_source, $primary_key) |
||
| 47 | |||
| 48 | |||
| 49 | /******************************************************************************** |
||
| 50 | * IDataSource implementation * |
||
| 51 | ********************************************************************************/ |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Get count of data |
||
| 56 | * @return int |
||
| 57 | */ |
||
| 58 | public function getCount() |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the data |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | public function getData() |
||
| 75 | |||
| 76 | |||
| 77 | /** |
||
| 78 | * Filter data - get one row |
||
| 79 | * @param array $condition |
||
| 80 | * @return static |
||
| 81 | */ |
||
| 82 | public function filterOne(array $condition) |
||
| 92 | |||
| 93 | |||
| 94 | /** |
||
| 95 | * Filter by date |
||
| 96 | * @param Filter\FilterDate $filter |
||
| 97 | * @return static |
||
| 98 | */ |
||
| 99 | public function applyFilterDate(Filter\FilterDate $filter) |
||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * Filter by date range |
||
| 117 | * @param Filter\FilterDateRange $filter |
||
| 118 | * @return void |
||
| 119 | */ |
||
| 120 | public function applyFilterDateRange(Filter\FilterDateRange $filter) |
||
| 142 | |||
| 143 | |||
| 144 | /** |
||
| 145 | * Filter by range |
||
| 146 | * @param Filter\FilterRange $filter |
||
| 147 | * @return void |
||
| 148 | */ |
||
| 149 | public function applyFilterRange(Filter\FilterRange $filter) |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * Filter by keyword |
||
| 174 | * @param Filter\FilterText $filter |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | public function applyFilterText(Filter\FilterText $filter) |
||
| 210 | |||
| 211 | |||
| 212 | /** |
||
| 213 | * Filter by multi select value |
||
| 214 | * @param Filter\FilterMultiSelect $filter |
||
| 215 | * @return void |
||
| 216 | */ |
||
| 217 | public function applyFilterMultiSelect(Filter\FilterMultiSelect $filter) |
||
| 235 | |||
| 236 | |||
| 237 | /** |
||
| 238 | * Filter by select value |
||
| 239 | * @param Filter\FilterSelect $filter |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | public function applyFilterSelect(Filter\FilterSelect $filter) |
||
| 246 | |||
| 247 | |||
| 248 | /** |
||
| 249 | * Apply limit and offset on data |
||
| 250 | * @param int $offset |
||
| 251 | * @param int $limit |
||
| 252 | * @return static |
||
| 253 | */ |
||
| 254 | public function limit($offset, $limit) |
||
| 260 | |||
| 261 | |||
| 262 | /** |
||
| 263 | * Sort data |
||
| 264 | * @param Sorting $sorting |
||
| 265 | * @return static |
||
| 266 | */ |
||
| 267 | public function sort(Sorting $sorting) |
||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * Adjust column from DataGrid 'foreignKey.column' to Nextras 'this->foreignKey->column' |
||
| 302 | * @param string $column |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | private function prepareColumn($column) |
||
| 312 | } |
||
| 313 |
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..