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 Movies extends Model{ |
|
|
|||
15 | |||
16 | |||
17 | /** |
||
18 | * Décrit le nom de la table |
||
19 | * que classe fait référence |
||
20 | */ |
||
21 | protected $table = 'movies'; |
||
22 | |||
23 | |||
24 | |||
25 | /** |
||
26 | * Retourne tous les films |
||
27 | */ |
||
28 | public function getAllMovies(){ |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Return moyenne des notes de presse |
||
38 | */ |
||
39 | public function getAvgNotePresse(){ |
||
47 | |||
48 | /***************************************************** Relationships ***********************************************************/ |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Retourne la catégorie à laquelle appartient un objet film |
||
53 | * Many To One : n..1 |
||
54 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
55 | */ |
||
56 | public function categories() |
||
60 | |||
61 | /** |
||
62 | * belongsToMany(): Many To Many |
||
63 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
64 | */ |
||
65 | public function actors() |
||
69 | |||
70 | public function directors() |
||
74 | |||
75 | public function comments() |
||
79 | |||
80 | public function sessions() |
||
84 | |||
85 | public function recommandations() |
||
89 | |||
90 | |||
91 | |||
92 | |||
93 | |||
94 | |||
95 | } |
||
96 | |||
99 |
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.