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 |
||
| 10 | trait SortableTrait |
||
| 11 | { |
||
| 12 | public static function bootSortableTrait() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Modify the order column value. |
||
| 23 | */ |
||
| 24 | public function setHighestOrderNumber() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Determine the order value for the new record. |
||
| 33 | */ |
||
| 34 | public function getHighestOrderNumber(): int |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Let's be nice and provide an ordered scope. |
||
| 41 | * |
||
| 42 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 43 | * @param string $direction |
||
| 44 | * |
||
| 45 | * @return \Illuminate\Database\Query\Builder |
||
| 46 | */ |
||
| 47 | public function scopeOrdered(Builder $query, string $direction = 'asc') |
||
| 51 | |||
| 52 | /** |
||
| 53 | * This function reorders the records: the record with the first id in the array |
||
| 54 | * will get order 1, the record with the second it will get order 2, ... |
||
| 55 | * |
||
| 56 | * A starting order number can be optionally supplied (defaults to 1). |
||
| 57 | * |
||
| 58 | * @param array|\ArrayAccess $ids |
||
| 59 | * @param int $startOrder |
||
| 60 | * @param string $primaryKeyColumn |
||
| 61 | */ |
||
| 62 | public static function setNewOrder($ids, int $startOrder = 1, string $primaryKeyColumn = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * This function reorders the records using an alternate column |
||
| 85 | * than the model's primary key. |
||
| 86 | * |
||
| 87 | * A starting order number can be optionally supplied (defaults to 1). |
||
| 88 | * |
||
| 89 | * @param string $primaryKeyColumn |
||
| 90 | * @param array|\ArrayAccess $ids |
||
| 91 | * @param int $startOrder |
||
| 92 | */ |
||
| 93 | public static function setNewOrderByCustomColumn(string $primaryKeyColumn, $ids, int $startOrder = 1) |
||
| 97 | |||
| 98 | /* |
||
| 99 | * Determine the column name of the order column. |
||
| 100 | */ |
||
| 101 | protected function determineOrderColumnName(): string |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Determine if the order column should be set when saving a new model instance. |
||
| 115 | */ |
||
| 116 | public function shouldSortWhenCreating(): bool |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Swaps the order of this model with the model 'below' this model. |
||
| 123 | * |
||
| 124 | * @return $this |
||
| 125 | */ |
||
| 126 | View Code Duplication | public function moveOrderDown() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Swaps the order of this model with the model 'above' this model. |
||
| 144 | * |
||
| 145 | * @return $this |
||
| 146 | */ |
||
| 147 | View Code Duplication | public function moveOrderUp() |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Swap the order of this model with the order of another model. |
||
| 165 | * |
||
| 166 | * @param \Spatie\EloquentSortable\Sortable $otherModel |
||
| 167 | * |
||
| 168 | * @return $this |
||
| 169 | */ |
||
| 170 | public function swapOrderWithModel(Sortable $otherModel) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Swap the order of two models. |
||
| 187 | * |
||
| 188 | * @param \Spatie\EloquentSortable\Sortable $model |
||
| 189 | * @param \Spatie\EloquentSortable\Sortable $otherModel |
||
| 190 | */ |
||
| 191 | public static function swapOrder(Sortable $model, Sortable $otherModel) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Moves this model to the first position. |
||
| 198 | * |
||
| 199 | * @return $this |
||
| 200 | */ |
||
| 201 | public function moveToStart() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Moves this model to the last position. |
||
| 223 | * |
||
| 224 | * @return $this |
||
| 225 | */ |
||
| 226 | public function moveToEnd() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Build eloquent builder of sortable. |
||
| 250 | * |
||
| 251 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 252 | */ |
||
| 253 | public function buildSortQuery() |
||
| 257 | } |
||
| 258 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.