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 |
||
14 | View Code Duplication | class User extends Model{ |
|
|
|||
15 | |||
16 | |||
17 | /** |
||
18 | * Décrit le nom de la table |
||
19 | * que classe fait référence |
||
20 | */ |
||
21 | protected $table = 'user'; |
||
22 | |||
23 | /** |
||
24 | * Retourne les 24 derniers utilisateurs |
||
25 | */ |
||
26 | public function getLastUsers(){ |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Retourne tous les films |
||
43 | */ |
||
44 | public function getAllMovies(){ |
||
49 | |||
50 | |||
51 | |||
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | |||
58 | /** |
||
59 | * Retourne la catégorie à laquelle appartient un objet film |
||
60 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
61 | */ |
||
62 | public function categories() |
||
66 | |||
67 | |||
68 | public function comments() |
||
72 | |||
73 | public function actors() |
||
77 | |||
78 | public function directors() |
||
82 | |||
83 | public function sessions() |
||
87 | |||
88 | public function recommandations() |
||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
97 | |||
98 | } |
||
99 | |||
102 |
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.