| Conditions | 11 |
| Paths | 324 |
| Total Lines | 107 |
| Code Lines | 66 |
| 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 | //return $team1Scores; |
||
| 106 | $team2Scores = $this->getTeamNetScore($team2, $holesData); |
||
| 107 | |||
| 108 | $team1Points = $this->calculatePoints($team1Scores, $team2Scores); |
||
| 109 | $team2Points = $this->calculatePoints($team2Scores, $team1Scores); |
||
| 110 | |||
| 111 | //Save Points in Teammatches |
||
| 112 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points)); |
||
| 113 | Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points)); |
||
| 114 | |||
| 115 | |||
| 116 | //Need to determine if same amount of scores are in both |
||
| 117 | // If not then do not return |
||
| 118 | |||
| 119 | foreach($team1Scores as $key=>$teamScore){ |
||
| 120 | if($teamScore <= 0){ |
||
| 121 | $team1Scores[$key] = ''; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | foreach($team2Scores as $key=>$teamScore){ |
||
| 126 | if($teamScore <= 0){ |
||
| 127 | $team2Scores[$key] = ''; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $team[0] = [ |
||
| 132 | "team" => $team1Name[0]['name'], |
||
| 133 | "hole1" => $team1Scores[0], |
||
| 134 | "hole2" => $team1Scores[1], |
||
| 135 | "hole3" => $team1Scores[2], |
||
| 136 | "hole4" => $team1Scores[3], |
||
| 137 | "hole5" => $team1Scores[4], |
||
| 138 | "hole6" => $team1Scores[5], |
||
| 139 | "hole7" => $team1Scores[6], |
||
| 140 | "hole8" => $team1Scores[7], |
||
| 141 | "hole9" => $team1Scores[8], |
||
| 142 | "points" =>$team1Points |
||
| 143 | ]; |
||
| 144 | |||
| 145 | $team[1] = [ |
||
| 146 | "team" => $team2Name[0]['name'], |
||
| 147 | "hole1" => $team2Scores[0], |
||
| 148 | "hole2" => $team2Scores[1], |
||
| 149 | "hole3" => $team2Scores[2], |
||
| 150 | "hole4" => $team2Scores[3], |
||
| 151 | "hole5" => $team2Scores[4], |
||
| 152 | "hole6" => $team2Scores[5], |
||
| 153 | "hole7" => $team2Scores[6], |
||
| 154 | "hole8" => $team2Scores[7], |
||
| 155 | "hole9" => $team2Scores[8], |
||
| 156 | "points" => $team2Points |
||
| 157 | ]; |
||
| 158 | |||
| 159 | $data['data'] = $team; |
||
| 160 | return $data; |
||
| 161 | } |
||
| 162 | |||
| 306 |
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.