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 |
||
8 | class Channel extends Model |
||
9 | { |
||
10 | protected $fillable = [ |
||
11 | 'name', |
||
12 | 'slug' |
||
13 | ]; |
||
14 | |||
15 | public $timestamps = false; |
||
16 | |||
17 | public function getCssClassesAttribute() |
||
26 | |||
27 | public function subscriptions() |
||
31 | |||
32 | public function subscribers() |
||
36 | |||
37 | public function subscribersExcept() |
||
41 | |||
42 | View Code Duplication | public function attachSubscriber($user) |
|
51 | |||
52 | public function detachSubscriber($user) |
||
59 | |||
60 | public function resolveChildRouteBinding($childType, $value, $field) |
||
64 | |||
65 | public function getRouteKeyName() |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.