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 FightersGroup extends Model |
||
10 | { |
||
11 | protected $table = 'fighters_groups'; |
||
12 | public $timestamps = true; |
||
13 | protected $guarded = ['id']; |
||
14 | |||
15 | /** |
||
16 | * Check if Request contains tournamentSlug / Should Move to TreeRequest When Built. |
||
17 | * |
||
18 | * @param $request |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public static function hasTournamentInRequest($request) |
||
26 | |||
27 | /** |
||
28 | * Check if Request contains championshipId / Should Move to TreeRequest When Built. |
||
29 | * |
||
30 | * @param $request |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | public static function hasChampionshipInRequest($request) |
||
38 | |||
39 | /** |
||
40 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
41 | */ |
||
42 | public function championship() |
||
46 | |||
47 | /** |
||
48 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
49 | */ |
||
50 | public function fights() |
||
54 | |||
55 | public function teams() |
||
59 | |||
60 | public function competitors() |
||
64 | |||
65 | /** |
||
66 | * @param $settings |
||
67 | * @param Championship $championship |
||
68 | */ |
||
69 | public static function generateFights(Collection $fightersGroup, $settings, Championship $championship = null) |
||
87 | |||
88 | /** |
||
89 | * Supercharge of sync Many2Many function. |
||
90 | * Original sync doesn't insert NULL ids. |
||
91 | * |
||
92 | * @param $fighters |
||
93 | */ |
||
94 | View Code Duplication | public function syncTeams($fighters) |
|
108 | |||
109 | /** |
||
110 | * Supercharge of sync Many2Many function. |
||
111 | * Original sync doesn't insert NULL ids. |
||
112 | * |
||
113 | * @param $fighters |
||
114 | */ |
||
115 | View Code Duplication | public function syncCompetitors($fighters) |
|
128 | } |
||
129 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.