| Conditions | 15 |
| Paths | 192 |
| Total Lines | 56 |
| Code Lines | 39 |
| Lines | 14 |
| Ratio | 25 % |
| Changes | 0 | ||
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 |
||
| 51 | public function store(Request $request, Championship $championship) |
||
| 52 | { |
||
| 53 | DB::table('fight')->delete(); |
||
| 54 | DB::table('fighters_groups')->delete(); |
||
| 55 | DB::table('fighters_group_competitor')->delete(); |
||
| 56 | DB::table('fighters_group_team')->delete(); |
||
| 57 | DB::table('competitor')->delete(); |
||
| 58 | DB::table('users')->where('id', '<>', 1)->delete(); |
||
| 59 | |||
| 60 | $championship = Championship::with('teams', 'users', 'category', 'settings')->find($championship->id); |
||
| 61 | $numFighters = $request->numFighters; |
||
| 62 | |||
| 63 | $users = factory(User::class, (int)$numFighters)->create(); |
||
| 64 | |||
| 65 | View Code Duplication | foreach ($users as $user) { |
|
| 66 | factory(Competitor::class)->create([ |
||
| 67 | 'championship_id' => $championship->id, |
||
| 68 | 'user_id' => $user->id, |
||
| 69 | 'confirmed' => 1, |
||
| 70 | 'short_id' => $user->id |
||
| 71 | ]); |
||
| 72 | } |
||
| 73 | $championship->settings = ChampionshipSettings::createOrUpdate($request, $championship); |
||
| 74 | |||
| 75 | $generation = new TreeGen($championship, null); |
||
| 76 | //TODO Set groupBy argument to NULL for now |
||
| 77 | if ($championship->hasPreliminary() && $championship->category->isTeam()) { |
||
| 78 | $generation = new PlayOffTeamTreeGen($championship, null); |
||
| 79 | } |
||
| 80 | if ($championship->hasPreliminary() && !$championship->category->isTeam()) { |
||
| 81 | $generation = new PlayOffCompetitorTreeGen($championship, null); |
||
| 82 | } |
||
| 83 | View Code Duplication | if (!$championship->hasPreliminary() && $championship->isDirectEliminationType() && $championship->category->isTeam()) { |
|
| 84 | $generation = new DirectEliminationTeamTreeGen($championship, null); |
||
| 85 | } |
||
| 86 | View Code Duplication | if (!$championship->hasPreliminary() && $championship->isDirectEliminationType() && !$championship->category->isTeam()) { |
|
| 87 | $generation = new DirectEliminationCompetitorTreeGen($championship, null); |
||
| 88 | } |
||
| 89 | |||
| 90 | $fighterToUpdate = null; |
||
| 91 | try { |
||
| 92 | $generation->run(); |
||
| 93 | FightersGroup::generateFights($championship); |
||
| 94 | // For Now, We don't generate fights when Preliminary |
||
| 95 | if ($championship->isDirectEliminationType() && !$championship->hasPreliminary()) { |
||
| 96 | FightersGroup::generateNextRoundsFights($championship); |
||
| 97 | } |
||
| 98 | } catch (TreeGenerationException $e) { |
||
| 99 | redirect()->back() |
||
| 100 | ->withErrors([$numFighters . "-" . $e->getMessage()]); |
||
| 101 | } |
||
| 102 | return redirect()->back() |
||
| 103 | ->with('numFighters', $numFighters) |
||
| 104 | ->with('hasPreliminary', $championship->settings->hasPreliminary) |
||
| 105 | ->with(['success', "Success"]); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.