Conditions | 8 |
Paths | 66 |
Total Lines | 56 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
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 |
||
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 | // FIXME: need to look up / overwrite existing team results as applicable: |
||
96 | // home team result: |
||
97 | $team_result = new TeamResult(); |
||
98 | $team_result->schedule_id = $submission->match->schedule_id; |
||
99 | $team_result->match_id = $submission->match->id; |
||
100 | $team_result->team_id = $result->home_team_id; |
||
101 | $team_result->points = $result->home_team_score; |
||
102 | $team_result->win = $result->home_team_id == $submission->win_team_id ? 1 : 0; |
||
103 | $team_result->loss = $result->home_team_id != $submission->win_team_id ? 1 : 0; |
||
104 | $team_result->tie = 0; |
||
105 | $team_result->save(); |
||
106 | |||
107 | // away team result; |
||
108 | $team_result = new TeamResult(); |
||
109 | $team_result->schedule_id = $submission->match->schedule_id; |
||
110 | $team_result->match_id = $submission->match->id; |
||
111 | $team_result->team_id = $result->away_team_id; |
||
112 | $team_result->points = $result->away_team_score; |
||
113 | $team_result->win = $result->away_team_id == $submission->win_team_id ? 1 : 0; |
||
114 | $team_result->loss = $result->away_team_id != $submission->win_team_id ? 1 : 0; |
||
115 | $team_result->tie = 0; |
||
116 | $team_result->save(); |
||
117 | |||
118 | $submission->approved = TRUE; |
||
119 | $submission->save(); |
||
120 | } |
||
121 | |||
122 | $url = $request->url; |
||
123 | |||
124 | if (!empty($url)) { |
||
125 | return redirect($url)->with('success', 'Data saved successfully!'); |
||
126 | } |
||
127 | |||
128 | return redirect()->route('user', ['id' => \Auth::user()->id]); |
||
129 | } |
||
142 |