1 | <?php |
||
11 | class Championship extends Model |
||
12 | { |
||
13 | use SoftDeletes; |
||
14 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
||
15 | protected $table = 'championship'; |
||
16 | |||
17 | public $timestamps = true; |
||
18 | protected $fillable = [ |
||
19 | 'tournament_id', |
||
20 | 'category_id', |
||
21 | ]; |
||
22 | |||
23 | protected static function boot() |
||
24 | { |
||
25 | parent::boot(); |
||
26 | |||
27 | static::deleting(function ($championship) { |
||
28 | $championship->competitors()->delete(); |
||
29 | $championship->settings()->delete(); |
||
30 | }); |
||
31 | static::restoring(function ($championship) { |
||
32 | $championship->competitors()->restore(); |
||
33 | $championship->settings()->restore(); |
||
34 | }); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * A championship has many Competitors. |
||
39 | * |
||
40 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
41 | */ |
||
42 | public function competitors() |
||
43 | { |
||
44 | return $this->hasMany(Competitor::class); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * A championship has many Competitors. |
||
49 | * |
||
50 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
51 | */ |
||
52 | public function competitorsWithUser() |
||
53 | { |
||
54 | return $this->hasMany(Competitor::class)->with('user'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * A championship belongs to a Category. |
||
59 | * |
||
60 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
61 | */ |
||
62 | public function category() |
||
63 | { |
||
64 | return $this->belongsTo(Category::class); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * A championship belongs to a Tournament. |
||
69 | * |
||
70 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
71 | */ |
||
72 | public function tournament() |
||
73 | { |
||
74 | return $this->belongsTo(Tournament::class); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get All competitors from a Championships. |
||
79 | * |
||
80 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
81 | */ |
||
82 | public function users() |
||
83 | { |
||
84 | return $this->belongsToMany(User::class, 'competitor', 'championship_id') |
||
85 | ->withPivot('confirmed') |
||
86 | ->withTimestamps(); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * A championship only has 1 Settings. |
||
91 | * |
||
92 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
93 | */ |
||
94 | public function settings() |
||
95 | { |
||
96 | return $this->hasOne(ChampionshipSettings::class); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * A championship has Many Teams. |
||
101 | * |
||
102 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
103 | */ |
||
104 | public function teams() |
||
105 | { |
||
106 | return $this->hasMany(Team::class); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Check if Championship has Preliminary Round Configured. |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function hasPreliminary() |
||
115 | { |
||
116 | return $this->settings == null || $this->settings->hasPreliminary; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Check if 2nd Round of Championship is Round Robin. |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function isPlayOffType() |
||
125 | { |
||
126 | return $this->settings != null && $this->settings->treeType == ChampionshipSettings::PLAY_OFF; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Check if 2nd Round of Championship is Direct Elimination. |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isDirectEliminationType() |
||
135 | { |
||
136 | return $this->settings != null && $this->settings->treeType == ChampionshipSettings::DIRECT_ELIMINATION; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * A championship has Many Groups of Fighters. |
||
141 | * |
||
142 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
143 | */ |
||
144 | public function fightersGroups() |
||
145 | { |
||
146 | return $this->hasMany(FightersGroup::class); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * A championship has Many fights. |
||
151 | * |
||
152 | * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough |
||
153 | */ |
||
154 | public function fights() |
||
158 | |||
159 | /** |
||
160 | * Get the fights that happen to the first round |
||
161 | * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough |
||
162 | */ |
||
163 | public function firstRoundFights() |
||
169 | |||
170 | private function hasNoCustomSettings() |
||
181 | |||
182 | public function buildName() |
||
203 | |||
204 | public function getSettings() |
||
208 | |||
209 | /** |
||
210 | * Return Groups that belongs to a round |
||
211 | * @param $round |
||
212 | * @return HasMany |
||
213 | */ |
||
214 | public function groupsByRound($round) |
||
218 | |||
219 | /** |
||
220 | * Return Fights that belongs to a round |
||
221 | * |
||
222 | * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough |
||
223 | */ |
||
224 | public function fightsByRound($round) |
||
225 | { |
||
226 | return $this->hasManyThrough(Fight::class, FightersGroup::class)->where('round',$round); |
||
227 | } |
||
228 | } |
||
229 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.