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 |
||
24 | View Code Duplication | class Model extends Eloquent\Model |
|
|
|||
25 | { |
||
26 | use Eloquent\SoftDeletes; |
||
27 | |||
28 | /** |
||
29 | * We do not want any timestamps. |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | public $timestamps = false; |
||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $dates = ['deleted_at']; |
||
38 | /** |
||
39 | * The attributes that are not mass assignable. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $guarded = []; |
||
44 | |||
45 | 4 | public static function boot() |
|
53 | |||
54 | /** |
||
55 | * Make of this model. |
||
56 | * |
||
57 | * @return Eloquent\Relations\BelongsTo |
||
58 | */ |
||
59 | public function make() |
||
63 | |||
64 | /** |
||
65 | * Guitars of this model. |
||
66 | * |
||
67 | * @return Eloquent\Relations\HasMany |
||
68 | */ |
||
69 | public function guitars() |
||
73 | } |
||
74 |
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.