| Conditions | 10 |
| Paths | 258 |
| Total Lines | 71 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 73 | public function update(Request $request, $id) |
||
| 74 | { |
||
| 75 | $submission = ResultSubmission::find($id); |
||
| 76 | |||
| 77 | if ($request->delete == 'delete') { |
||
| 78 | $submission->delete(); |
||
| 79 | } |
||
| 80 | else { |
||
| 81 | $result = Result::where('match_id', $submission->match_id)->first(); |
||
| 82 | |||
| 83 | if (empty($result)) { |
||
| 84 | $result = new Result(); |
||
| 85 | $result->match_id = $submission->match_id; |
||
| 86 | } |
||
| 87 | |||
| 88 | $result->home_team_id = $submission->match->home_team_id; |
||
| 89 | $result->away_team_id = $submission->match->away_team_id; |
||
| 90 | $result->home_team_score = $submission->home_team_score; |
||
| 91 | $result->away_team_score = $submission->away_team_score; |
||
| 92 | |||
| 93 | $result->save(); |
||
| 94 | |||
| 95 | // home team result: |
||
| 96 | $team_result = TeamResult::where('schedule_id', $submission->match->schedule_id) |
||
| 97 | ->where('match_id', $submission->match_id) |
||
| 98 | ->where('team_id', $result->home_team_id) |
||
| 99 | ->first(); |
||
| 100 | |||
| 101 | if (empty($team_result)) { |
||
| 102 | $team_result = new TeamResult(); |
||
| 103 | $team_result->schedule_id = $submission->match->schedule_id; |
||
| 104 | $team_result->match_id = $submission->match->id; |
||
| 105 | $team_result->team_id = $result->home_team_id; |
||
| 106 | } |
||
| 107 | |||
| 108 | $team_result->points = $result->home_team_score; |
||
| 109 | $team_result->win = $result->home_team_id == $submission->win_team_id ? 1 : 0; |
||
| 110 | $team_result->loss = $result->home_team_id != $submission->win_team_id ? 1 : 0; |
||
| 111 | $team_result->tie = 0; |
||
| 112 | $team_result->save(); |
||
| 113 | |||
| 114 | // away team result; |
||
| 115 | $team_result = TeamResult::where('schedule_id', $submission->match->schedule_id) |
||
| 116 | ->where('match_id', $submission->match_id) |
||
| 117 | ->where('team_id', $result->away_team_id) |
||
| 118 | ->first(); |
||
| 119 | |||
| 120 | if (empty($team_result)) { |
||
| 121 | $team_result = new TeamResult(); |
||
| 122 | $team_result->schedule_id = $submission->match->schedule_id; |
||
| 123 | $team_result->match_id = $submission->match->id; |
||
| 124 | $team_result->team_id = $result->away_team_id; |
||
| 125 | } |
||
| 126 | |||
| 127 | $team_result->points = $result->away_team_score; |
||
| 128 | $team_result->win = $result->away_team_id == $submission->win_team_id ? 1 : 0; |
||
| 129 | $team_result->loss = $result->away_team_id != $submission->win_team_id ? 1 : 0; |
||
| 130 | $team_result->tie = 0; |
||
| 131 | $team_result->save(); |
||
| 132 | |||
| 133 | $submission->approved = TRUE; |
||
| 134 | $submission->save(); |
||
| 135 | } |
||
| 136 | |||
| 137 | $url = $request->url; |
||
| 138 | |||
| 139 | if (!empty($url)) { |
||
| 140 | return redirect($url)->with('success', 'Data saved successfully!'); |
||
| 141 | } |
||
| 142 | |||
| 143 | return redirect()->route('user', ['id' => \Auth::user()->id]); |
||
| 144 | } |
||
| 157 |