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 |
||
10 | class Round extends Model |
||
11 | { |
||
12 | protected $table = 'round'; |
||
13 | public $timestamps = true; |
||
14 | protected $guarded = ['id']; |
||
15 | |||
16 | /** |
||
17 | * Check if Request contains tournamentSlug / Should Move to TreeRequest When Built |
||
18 | * @param $request |
||
19 | * @return bool |
||
20 | */ |
||
21 | public static function hasTournamentInRequest($request) |
||
25 | |||
26 | /** |
||
27 | * Check if Request contains championshipId / Should Move to TreeRequest When Built |
||
28 | * @param $request |
||
29 | * @return bool |
||
30 | */ |
||
31 | public static function hasChampionshipInRequest($request) |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
39 | */ |
||
40 | public function championship() |
||
44 | |||
45 | /** |
||
46 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
47 | */ |
||
48 | public function fights() |
||
52 | |||
53 | public function teams() |
||
57 | |||
58 | public function competitors() |
||
62 | |||
63 | |||
64 | /** |
||
65 | * @param $settings |
||
66 | * @param Championship $championship |
||
67 | */ |
||
68 | public static function generateFights(Collection $rounds, $settings, Championship $championship = null) |
||
87 | |||
88 | |||
89 | /** |
||
90 | * Supercharge of sync Many2Many function. |
||
91 | * Original sync doesn't insert NULL ids |
||
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 | * @param $fighters |
||
113 | */ |
||
114 | View Code Duplication | public function syncCompetitors($fighters) |
|
127 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.