Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 5 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
111 | public function update(Request $request, Championship $championship) |
||
112 | { |
||
113 | $tree = $championship->chooseGenerationStrategy(); |
||
114 | $fighters = $request->fighters; |
||
115 | $tree->update($request); |
||
116 | |||
117 | // $query = FightersGroup::with('fights') |
||
118 | // ->where('championship_id', $championship->id); |
||
119 | // |
||
120 | // $numFighter = 0; |
||
121 | // |
||
122 | // $scores = $request->score; |
||
123 | // if ($championship->hasPreliminary()) { |
||
124 | // $query = $query->where('round', '>', 1); |
||
125 | // $fighters = $request->preliminary_fighters; |
||
126 | // } |
||
127 | // $groups = $query->get(); |
||
128 | |||
129 | // foreach ($groups as $group) { |
||
130 | // foreach ($group->fights as $fight) { |
||
131 | // // Find the fight in array, and update order |
||
132 | // $oldC1 = $fight->c1; |
||
133 | // $oldC2 = $fight->c2; |
||
134 | // $fight->c1 = $fighters[$numFighter]; |
||
135 | // $scores[$numFighter] != null |
||
136 | // ? $fight->winner_id = $fighters[$numFighter] |
||
137 | // : $fight->winner_id = null; |
||
138 | // $numFighter++; |
||
139 | // |
||
140 | // $fight->c2 = $fighters[$numFighter]; |
||
141 | // if ($fight->winner_id == null) { |
||
142 | // $scores[$numFighter] != null |
||
143 | // ? $fight->winner_id = $fighters[$numFighter] |
||
144 | // : $fight->winner_id = null; |
||
145 | // } |
||
146 | // |
||
147 | // |
||
148 | // $numFighter++; |
||
149 | // $fight->save(); |
||
150 | // |
||
151 | // |
||
152 | // // Update group and group->competitor / group->team |
||
153 | // if ($championship->isSingleEliminationCompetitor()) { |
||
154 | // try { |
||
155 | // |
||
156 | // } catch (QueryException $exception) { |
||
157 | // |
||
158 | // } |
||
159 | // $fgc = FighterGroupCompetitor::where('fighters_group_id', $group->id) |
||
160 | // ->where('competitor_id', $oldC1) |
||
161 | // ->first(); |
||
162 | // |
||
163 | // $fgc->competitor_id = $fight->c1; |
||
164 | // $fgc->save(); |
||
165 | // |
||
166 | // $fgc = FighterGroupCompetitor::where('fighters_group_id', $group->id) |
||
167 | // ->where('competitor_id', $oldC2) |
||
168 | // ->first(); |
||
169 | // |
||
170 | // $fgc->competitor_id = $fight->c2; |
||
171 | // $fgc->save(); |
||
172 | // } |
||
173 | // if ($championship->isSingleEliminationTeam()) { |
||
174 | // $fgt = FighterGroupTeam::where('fighters_group_id', $group->id) |
||
175 | // ->where('team_id', $oldC1) |
||
176 | // ->first(); |
||
177 | // $fgt->team_id = $fight->c1; |
||
178 | // $fgt->save(); |
||
179 | // |
||
180 | // $fgt = FighterGroupTeam::where('fighters_group_id', $group->id) |
||
181 | // ->where('team_id', $oldC2) |
||
182 | // ->first(); |
||
183 | //// dd($group->id,$oldC2); |
||
184 | // $fgt->team_id = $fight->c2; |
||
185 | // $fgt->save(); |
||
186 | // |
||
187 | // } |
||
188 | // } |
||
189 | // } |
||
190 | return back(); |
||
191 | } |
||
192 | } |
||
193 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: