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 |
||
9 | class Player extends DsManagerOrm |
||
10 | { |
||
11 | /** |
||
12 | * |
||
13 | */ |
||
14 | const PLAYER_STATS_LIMIT = 5; |
||
15 | |||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $table = 'players'; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $fillable = [ |
||
26 | 'name', |
||
27 | 'surname', |
||
28 | 'age', |
||
29 | 'nationality', |
||
30 | 'skillAvg', |
||
31 | 'wageReq', |
||
32 | 'val', |
||
33 | 'role', |
||
34 | 'team_id' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
39 | */ |
||
40 | public function team() |
||
44 | |||
45 | /** |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function lastMatches() |
||
54 | |||
55 | /** |
||
56 | * @return mixed |
||
57 | */ |
||
58 | public function goals() |
||
64 | |||
65 | /** |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function appearances() |
||
74 | |||
75 | /** |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public function avg() |
||
84 | |||
85 | /** |
||
86 | * @param $query |
||
87 | * @return mixed |
||
88 | */ |
||
89 | public function scopeStatistics($query) |
||
99 | |||
100 | /** |
||
101 | * @return array |
||
102 | */ |
||
103 | View Code Duplication | public static function getBest() |
|
116 | } |
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.