Conditions | 16 |
Paths | 2916 |
Total Lines | 122 |
Code Lines | 74 |
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 | |||
58 | |||
59 | $group = Input::get('group'); |
||
60 | |||
61 | |||
62 | $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group); |
||
63 | |||
64 | //Create Player data |
||
65 | $matchUp = array(); |
||
66 | foreach($groupPlayers as $key=>$groupPlayer){ |
||
67 | $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
||
68 | $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
||
69 | foreach ($groupPlayer->round as $round){ |
||
70 | $matchUp[$key]['team'] = $round->team_id; |
||
71 | $matchUp[$key]['course'] = $round->course_id; |
||
72 | $matchUp[$key]['holescores'] = $round->holescores; |
||
73 | } |
||
74 | |||
75 | } |
||
76 | |||
77 | // Change lowest handicap to ZERO and change others to reflect it |
||
78 | foreach($matchUp as $key=>$match){ |
||
79 | $matchHandicaps[] = $match['matchHandicap']; |
||
80 | } |
||
81 | $lowestMatchHandicap = min($matchHandicaps); |
||
82 | //handicap change |
||
83 | $handicapChange = $lowestMatchHandicap * -1; |
||
84 | foreach($matchUp as $key=>$match){ |
||
85 | $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
||
86 | } |
||
87 | |||
88 | // Separate two teams |
||
89 | $team1 = array(array_shift ($matchUp)); |
||
90 | $team1Id = $team1[0]['team']; |
||
91 | $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
||
92 | foreach($matchUp as $key=>$match){ |
||
93 | if($match['team'] == $team1[0]['team']){ |
||
94 | $team1[] = $match; |
||
95 | unset($matchUp[$key]); |
||
96 | } |
||
97 | } |
||
98 | $team2 = $matchUp; |
||
99 | $team2Id = $team2[1]['team']; |
||
100 | $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray(); |
||
101 | |||
102 | $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get(); |
||
103 | |||
104 | $team1Scores = $this->getTeamNetScore($team1, $holesData); |
||
105 | $team2Scores = $this->getTeamNetScore($team2, $holesData); |
||
106 | |||
107 | $team1Points = $this->calculatePoints($team1Scores, $team2Scores); |
||
108 | $team2Points = $this->calculatePoints($team2Scores, $team1Scores); |
||
109 | |||
110 | // Bonus point logic |
||
111 | // Occurs after 9th hole score is added to both teams |
||
112 | |||
113 | if($team1Scores[8] != null && $team2Scores[8] != null){ |
||
114 | if($team1Points > $team2Points){ |
||
115 | $team1Points = $team1Points + 1; |
||
116 | } |
||
117 | if($team2Points > $team1Points){ |
||
118 | $team2Points = $team2Points + 1; |
||
119 | } |
||
120 | if($team1Points == $team2Points){ |
||
121 | $team1Points = $team1Points + .5; |
||
122 | $team2Points = $team2Points + .5; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | //Save Points in Teammatches |
||
127 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points)); |
||
128 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points)); |
||
129 | |||
130 | |||
131 | //Need to determine if same amount of scores are in both |
||
132 | // If not then do not return |
||
133 | |||
134 | foreach($team1Scores as $key=>$teamScore){ |
||
135 | if($teamScore <= 0){ |
||
136 | $team1Scores[$key] = ''; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | foreach($team2Scores as $key=>$teamScore){ |
||
141 | if($teamScore <= 0){ |
||
142 | $team2Scores[$key] = ''; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | $team[0] = [ |
||
147 | "team" => $team1Name[0]['name'], |
||
148 | "hole1" => $team1Scores[0], |
||
149 | "hole2" => $team1Scores[1], |
||
150 | "hole3" => $team1Scores[2], |
||
151 | "hole4" => $team1Scores[3], |
||
152 | "hole5" => $team1Scores[4], |
||
153 | "hole6" => $team1Scores[5], |
||
154 | "hole7" => $team1Scores[6], |
||
155 | "hole8" => $team1Scores[7], |
||
156 | "hole9" => $team1Scores[8], |
||
157 | "points" =>$team1Points |
||
158 | ]; |
||
159 | |||
160 | $team[1] = [ |
||
161 | "team" => $team2Name[0]['name'], |
||
162 | "hole1" => $team2Scores[0], |
||
163 | "hole2" => $team2Scores[1], |
||
164 | "hole3" => $team2Scores[2], |
||
165 | "hole4" => $team2Scores[3], |
||
166 | "hole5" => $team2Scores[4], |
||
167 | "hole6" => $team2Scores[5], |
||
168 | "hole7" => $team2Scores[6], |
||
169 | "hole8" => $team2Scores[7], |
||
170 | "hole9" => $team2Scores[8], |
||
171 | "points" => $team2Points |
||
172 | ]; |
||
173 | |||
174 | $data['data'] = $team; |
||
175 | return $data; |
||
176 | } |
||
177 | |||
312 |
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.