| Conditions | 6 |
| Paths | 4 |
| Total Lines | 89 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 46 | public function store(Series $series, Request $request) { |
||
| 47 | $validatedData = $request->validate([ |
||
|
|
|||
| 48 | 'name' => 'required|max:255', |
||
| 49 | ]); |
||
| 50 | |||
| 51 | $name = $request->name; |
||
| 52 | $association_id = $series->association->id; |
||
| 53 | $division_id = $request->division_id; |
||
| 54 | $start_date = $request->start_date; |
||
| 55 | $end_date = $request->end_date; |
||
| 56 | $weekday = $request->weekday; |
||
| 57 | |||
| 58 | $schedule = new Schedule; |
||
| 59 | |||
| 60 | $schedule->name = $name; |
||
| 61 | $schedule->association_id = $association_id; |
||
| 62 | $schedule->series_id = $series->id; |
||
| 63 | $schedule->division_id = $division_id; |
||
| 64 | $schedule->start_date = $start_date; |
||
| 65 | $schedule->end_date = $end_date; |
||
| 66 | |||
| 67 | $division = Division::where(['id' => $division_id])->first(); |
||
| 68 | |||
| 69 | if (!empty($division)) { |
||
| 70 | $schedule->name = $division->name; |
||
| 71 | $schedule->sequence = $division->sequence; |
||
| 72 | } |
||
| 73 | else { |
||
| 74 | $schedule->name = $schedule->start_date; |
||
| 75 | $schedule->sequence = null; |
||
| 76 | } |
||
| 77 | |||
| 78 | $schedule->save(); |
||
| 79 | |||
| 80 | if ($request->generate) { |
||
| 81 | $start_datetime = new \DateTime($start_date); |
||
| 82 | $end_datetime = new \DateTime($end_date); |
||
| 83 | |||
| 84 | $days_interval = $start_datetime->diff($end_datetime); |
||
| 85 | |||
| 86 | $days = $days_interval->format('%a'); |
||
| 87 | |||
| 88 | $association = Association::where(['id' => $association_id])->first(); |
||
| 89 | $venues = $association->venues; |
||
| 90 | |||
| 91 | $round_number = 1; |
||
| 92 | |||
| 93 | for ($i = 0; $i <= $days; $i += 1) { |
||
| 94 | if (strtolower($start_datetime->format('D')) == strtolower($weekday)) { |
||
| 95 | $round = new Round; |
||
| 96 | |||
| 97 | $round->schedule_id = $schedule->id; |
||
| 98 | $round->division_id = $division_id; |
||
| 99 | $round->series_id = $series->id; |
||
| 100 | |||
| 101 | $round->start_date = $start_datetime; |
||
| 102 | $round->end_date = $start_datetime; |
||
| 103 | $round->name = 'Round ' . $round_number; |
||
| 104 | |||
| 105 | $round->save(); |
||
| 106 | |||
| 107 | $round_number += 1; |
||
| 108 | |||
| 109 | foreach ($venues as $venue) { |
||
| 110 | $match = new Match; |
||
| 111 | |||
| 112 | $match->name = $venue->name . ' – ' . $round->start_date->format('m-d-Y'); |
||
| 113 | $match->association_id = $association->id; |
||
| 114 | $match->series_id = $series->id; |
||
| 115 | $match->division_id = $division->id; |
||
| 116 | |||
| 117 | // Unique key fields: |
||
| 118 | $match->schedule_id = $schedule->id; |
||
| 119 | $match->round_id = $round->id; |
||
| 120 | $match->venue_id = $venue->id; |
||
| 121 | $match->sequence = 1; |
||
| 122 | |||
| 123 | $match->start_date = $round->start_date; |
||
| 124 | $match->end_date = $round->end_date; |
||
| 125 | |||
| 126 | $match->save(); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | $start_datetime->add(new \DateInterval('P1D')); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | return redirect()->route('series.schedules', ['series' => $series]); |
||
| 135 | } |
||
| 171 |