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 |
||
7 | trait SortableTrait |
||
8 | { |
||
9 | public static function bootSortableTrait() |
||
17 | |||
18 | /** |
||
19 | * Modify the order column value. |
||
20 | */ |
||
21 | public function setHighestOrderNumber() |
||
26 | |||
27 | /** |
||
28 | * Determine the order value for the new record. |
||
29 | * |
||
30 | * @return int |
||
31 | */ |
||
32 | public function getHighestOrderNumber() |
||
36 | |||
37 | /** |
||
38 | * Let's be nice and provide an ordered scope. |
||
39 | * |
||
40 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
41 | * @param string $direction |
||
42 | * |
||
43 | * @return \Illuminate\Database\Query\Builder |
||
44 | */ |
||
45 | public function scopeOrdered(\Illuminate\Database\Eloquent\Builder $query, $direction = 'asc') |
||
49 | |||
50 | /** |
||
51 | * This function reorders the records: the record with the first id in the array |
||
52 | * will get order 1, the record with the second it will get order 2, ... |
||
53 | * |
||
54 | * A starting order number can be optionally supplied (defaults to 1). |
||
55 | * |
||
56 | * @param array $ids |
||
57 | * @param int $startOrder |
||
58 | * |
||
59 | * @throws SortableException |
||
60 | */ |
||
61 | public static function setNewOrder($ids, $startOrder = 1) |
||
76 | |||
77 | /** |
||
78 | * Determine the column name of the order column. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | protected function determineOrderColumnName() |
||
93 | |||
94 | /** |
||
95 | * Determine if the order column should be set when saving a new model instance. |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function shouldSortWhenCreating() |
||
111 | |||
112 | /** |
||
113 | * Swaps the order of this model with the model 'below' this model. |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | View Code Duplication | public function moveOrderDown() |
|
132 | |||
133 | /** |
||
134 | * Swaps the order of this model with the model 'above' this model. |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | View Code Duplication | public function moveOrderUp() |
|
153 | |||
154 | /** |
||
155 | * Swap the order of this model with the order of another model. |
||
156 | * |
||
157 | * @param \Spatie\EloquentSortable\Sortable $otherModel |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function swapOrderWithModel(Sortable $otherModel) |
||
175 | |||
176 | /** |
||
177 | * Swap the order of two models. |
||
178 | * |
||
179 | * @param \Spatie\EloquentSortable\Sortable $model |
||
180 | * @param \Spatie\EloquentSortable\Sortable $otherModel |
||
181 | */ |
||
182 | public static function swapOrder(Sortable $model, Sortable $otherModel) |
||
186 | |||
187 | /** |
||
188 | * Moves this model to the first position. |
||
189 | * |
||
190 | * @return $this |
||
191 | */ |
||
192 | public function moveToStart() |
||
211 | |||
212 | /** |
||
213 | * Moves this model to the last position. |
||
214 | * |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function moveToEnd() |
||
238 | } |
||
239 |
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.