Conditions | 19 |
Paths | 17496 |
Total Lines | 170 |
Code Lines | 97 |
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 |
||
55 | public function show($id) |
||
56 | { |
||
57 | $group = Input::get('group'); // Stay in controller |
||
58 | |||
59 | |||
60 | $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group); |
||
61 | |||
62 | // |
||
63 | // Create Player data from MatchRound Repo |
||
64 | // Takes group of players |
||
65 | // |
||
66 | // Creates data array for each player in the match |
||
67 | // |
||
68 | $matchUp = array(); |
||
69 | foreach($groupPlayers as $key=>$groupPlayer){ |
||
70 | $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
||
71 | $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
||
72 | foreach ($groupPlayer->round as $round){ |
||
73 | $matchUp[$key]['team'] = $round->team_id; |
||
74 | $matchUp[$key]['course'] = $round->course_id; |
||
75 | $matchUp[$key]['holescores'] = $round->holescores; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | // Change lowest handicap to ZERO and change others to reflect it |
||
80 | // Create array of each players handicap |
||
81 | foreach($matchUp as $key=>$match){ |
||
82 | $matchHandicaps[] = $match['matchHandicap']; |
||
83 | } |
||
84 | |||
85 | // Determine the lowest handicap in the group |
||
86 | $lowestMatchHandicap = min($matchHandicaps); |
||
87 | |||
88 | //handicapChange is the number of strokes to offset on the others handicap |
||
89 | $handicapChange = $lowestMatchHandicap * -1; |
||
90 | |||
91 | // Adjust all handicaps |
||
92 | foreach($matchUp as $key=>$match){ |
||
93 | $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
||
94 | } |
||
95 | |||
96 | // Separate group into two teams |
||
97 | |||
98 | foreach($matchUp as $key=>$item){ |
||
99 | $teamIds[$key] = $item['team']; |
||
100 | } |
||
101 | |||
102 | sort($teamIds); |
||
103 | |||
104 | //$teamIds = array_slice($teamIds, 1, -1); |
||
105 | $teamIds = array_unique($teamIds); |
||
106 | $teamIds = array_values($teamIds); //reset array keys |
||
107 | |||
108 | $team1Id = $teamIds[0]; |
||
109 | $team2Id = $teamIds[1]; |
||
110 | |||
111 | $team1 = array(); |
||
112 | $team2 = array(); |
||
113 | |||
114 | foreach($matchUp as $key=>$match){ |
||
115 | if($match['team'] ==$team1Id ){ |
||
116 | $team1[] = $matchUp[$key]; |
||
117 | } else { |
||
118 | $team2[] = $matchUp[$key]; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | |||
123 | $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
||
124 | foreach($matchUp as $key=>$match){ |
||
125 | if($match['team'] == $team1[0]['team']){ |
||
126 | $team1[] = $match; |
||
127 | unset($matchUp[$key]); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | $team2 = $matchUp; |
||
132 | |||
133 | $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray(); |
||
134 | |||
135 | $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get(); |
||
136 | |||
137 | $team1Scores = $this->getTeamNetScore($team1, $holesData); |
||
138 | $team2Scores = $this->getTeamNetScore($team2, $holesData); |
||
139 | |||
140 | $team1Points = $this->calculatePoints($team1Scores, $team2Scores); |
||
141 | $team2Points = $this->calculatePoints($team2Scores, $team1Scores); |
||
142 | |||
143 | // Bonus point logic |
||
144 | // Occurs after 9th hole score is added to both teams |
||
145 | |||
146 | $team1Bonus = null; |
||
147 | $team2Bonus = null; |
||
148 | |||
149 | if($team1Scores[8] != null && $team2Scores[8] != null){ |
||
150 | if($team1Points > $team2Points){ |
||
151 | $team1Points = $team1Points + 1; |
||
152 | $team1Bonus = 1; |
||
153 | } |
||
154 | if($team2Points > $team1Points){ |
||
155 | $team2Points = $team2Points + 1; |
||
156 | $team2Bonus = 1; |
||
157 | } |
||
158 | if($team1Points == $team2Points){ |
||
159 | $team1Points = $team1Points + .5; |
||
160 | $team1Bonus = .5; |
||
161 | $team2Points = $team2Points + .5; |
||
162 | $team2Bonus = .5; |
||
163 | } |
||
164 | } |
||
165 | |||
166 | //Save Points in Teammatches |
||
167 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points)); |
||
168 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points)); |
||
169 | |||
170 | |||
171 | //Need to determine if same amount of scores are in both |
||
172 | // If not then do not return |
||
173 | |||
174 | foreach($team1Scores as $key=>$teamScore){ |
||
175 | if($teamScore <= 0){ |
||
176 | $team1Scores[$key] = ''; |
||
177 | } |
||
178 | } |
||
179 | $team1Net = array_sum($team1Scores); |
||
180 | |||
181 | |||
182 | foreach($team2Scores as $key=>$teamScore){ |
||
183 | if($teamScore <= 0){ |
||
184 | $team2Scores[$key] = ''; |
||
185 | } |
||
186 | } |
||
187 | $team2Net = array_sum($team2Scores); |
||
188 | |||
189 | |||
190 | $team[0] = [ |
||
191 | "team" => $team1Name[0]['name'], |
||
192 | "hole1" => $team1Scores[0], |
||
193 | "hole2" => $team1Scores[1], |
||
194 | "hole3" => $team1Scores[2], |
||
195 | "hole4" => $team1Scores[3], |
||
196 | "hole5" => $team1Scores[4], |
||
197 | "hole6" => $team1Scores[5], |
||
198 | "hole7" => $team1Scores[6], |
||
199 | "hole8" => $team1Scores[7], |
||
200 | "hole9" => $team1Scores[8], |
||
201 | "bonus" => $team1Bonus, |
||
202 | "points" => $team1Points, |
||
203 | "netscore" => $team1Net |
||
204 | ]; |
||
205 | |||
206 | $team[1] = [ |
||
207 | "team" => $team2Name[0]['name'], |
||
208 | "hole1" => $team2Scores[0], |
||
209 | "hole2" => $team2Scores[1], |
||
210 | "hole3" => $team2Scores[2], |
||
211 | "hole4" => $team2Scores[3], |
||
212 | "hole5" => $team2Scores[4], |
||
213 | "hole6" => $team2Scores[5], |
||
214 | "hole7" => $team2Scores[6], |
||
215 | "hole8" => $team2Scores[7], |
||
216 | "hole9" => $team2Scores[8], |
||
217 | "bonus" => $team2Bonus, |
||
218 | "points" => $team2Points, |
||
219 | "netscore" => $team2Net, |
||
220 | ]; |
||
221 | |||
222 | $data['data'] = $team; |
||
223 | return $data; |
||
224 | } |
||
225 | |||
370 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.