1 | <?php |
||
8 | class Fight extends Model |
||
9 | { |
||
10 | /** |
||
11 | * Fight constructor. |
||
12 | */ |
||
13 | public function __construct($userId1 = null, $userId2 = null) |
||
14 | { |
||
15 | $this->c1 = $userId1; |
||
16 | $this->c2 = $userId2; |
||
17 | } |
||
18 | |||
19 | protected $table = 'fight'; |
||
20 | public $timestamps = true; |
||
21 | |||
22 | protected $fillable = [ |
||
23 | 'round_id', |
||
24 | 'c1', |
||
25 | 'c2', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @param Championship $championship |
||
30 | * |
||
31 | * @return mixed |
||
32 | */ |
||
33 | private static function getActorsToFights(Championship $championship, Round $round = null) |
||
34 | { |
||
35 | if ($championship->category->isTeam) { |
||
36 | $fighters = $round->teams; |
||
37 | if (count($fighters) % 2 != 0) { |
||
38 | $fighters->push(new Team(['name' => 'BYE'])); |
||
39 | } |
||
40 | } else { |
||
41 | $fighters = $round->competitors; |
||
42 | if (count($fighters) % 2 != 0) { |
||
43 | $fighters->push(new Competitor()); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return $fighters; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get First Fighter. |
||
52 | * |
||
53 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
54 | */ |
||
55 | public function competitor1() |
||
56 | { |
||
57 | return $this->belongsTo(Competitor::class, 'c1', 'id'); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get Second Fighter. |
||
62 | * |
||
63 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
64 | */ |
||
65 | public function competitor2() |
||
66 | { |
||
67 | return $this->belongsTo(Competitor::class, 'c2', 'id'); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get First Fighter. |
||
72 | * |
||
73 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
74 | */ |
||
75 | public function team1() |
||
79 | |||
80 | /** |
||
81 | * Get Second Fighter. |
||
82 | * |
||
83 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
84 | */ |
||
85 | public function team2() |
||
89 | |||
90 | /** |
||
91 | * Save a Fight. |
||
92 | * |
||
93 | * @param Collection $rounds |
||
94 | * @param int $numRound |
||
95 | */ |
||
96 | public static function savePreliminaryFightRound($rounds, $numRound = 1) |
||
137 | |||
138 | // public static function saveRoundRobinFight(Championship $championship, $tree) |
||
|
|||
139 | // { |
||
140 | // $championship->category->isTeam |
||
141 | // ? $fighters = $championship->teams |
||
142 | // : $fighters = $championship->users; |
||
143 | // |
||
144 | // $reverseFighters = $fighters->reverse(); |
||
145 | // $order = 0; |
||
146 | // foreach ($reverseFighters as $reverse) { |
||
147 | // foreach ($fighters as $fighter) { |
||
148 | // if ($fighter->id != $reverse->id) { |
||
149 | // $fight = new Fight(); |
||
150 | // $fight->tree_id = $tree[0]->id; |
||
151 | // $fight->c1 = $fighter->id; |
||
152 | // $fight->c2 = $reverse->id; |
||
153 | // $fight->order = $order++; |
||
154 | // $fight->area = 1; |
||
155 | // $fight->save(); |
||
156 | // $order++; |
||
157 | // } |
||
158 | // } |
||
159 | // } |
||
160 | // } |
||
161 | |||
162 | /** |
||
163 | * @param Collection $rounds |
||
164 | */ |
||
165 | public static function saveRoundRobinFights(Championship $championship, $rounds) |
||
203 | } |
||
204 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.