Completed
Push — master ( c863ac...248e4c )
by Michael
05:09
created
app/controllers/TeamMatchesController.php 3 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
 
7 7
 class TeamMatchesController extends \BaseController {
8 8
 
9
-    public function __construct(MatchService $match, MatchRoundRepository $matchRoundRepo, TeamMatchesRepository $teamMatchesRepository)
10
-    {
11
-        $this->match = $match;
12
-        $this->matchRoundRepo = $matchRoundRepo;
13
-        $this->teamMatchesRepo = $teamMatchesRepository;
14
-    }
15
-
16
-    /**
9
+	public function __construct(MatchService $match, MatchRoundRepository $matchRoundRepo, TeamMatchesRepository $teamMatchesRepository)
10
+	{
11
+		$this->match = $match;
12
+		$this->matchRoundRepo = $matchRoundRepo;
13
+		$this->teamMatchesRepo = $teamMatchesRepository;
14
+	}
15
+
16
+	/**
17 17
 	 * Display a listing of the resource.
18 18
 	 *
19 19
 	 * @return Response
@@ -56,211 +56,211 @@  discard block
 block discarded – undo
56 56
 	{
57 57
 
58 58
 
59
-        $group = Input::get('group');
59
+		$group = Input::get('group');
60 60
 
61 61
 
62
-        $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group);
62
+		$groupPlayers = $this->matchRoundRepo->matchGroup($id, $group);
63 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
-            }
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 74
 
75
-        }
75
+		}
76 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
-            }
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 87
 
88 88
 
89 89
 // Separate two teams
90
-        $team1 = array(array_shift ($matchUp));
91
-        $team1Id = $team1[0]['team'];
92
-        $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
93
-        foreach($matchUp as $key=>$match){
94
-            if($match['team'] == $team1[0]['team']){
95
-                $team1[] = $match;
96
-                unset($matchUp[$key]);
97
-            }
98
-        }
99
-        $team2 = $matchUp;
100
-        $team2Id = $team2[1]['team'];
101
-        $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray();
102
-
103
-            $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get();
104
-
105
-            $team1Scores = $this->getTeamNetScore($team1, $holesData);
106
-            $team2Scores = $this->getTeamNetScore($team2, $holesData);
107
-
108
-            $team1Points = $this->calculatePoints($team1Scores, $team2Scores);
109
-            $team2Points = $this->calculatePoints($team2Scores, $team1Scores);
110
-
111
-            // Bonus point logic
112
-            // Occurs after 9th hole score is added to both teams
113
-
114
-            if($team1Scores[8] != null && $team2Scores[8] != null){
115
-                if($team1Points > $team2Points){
116
-                    $team1Points = $team1Points + 1;
117
-                }
118
-                if($team2Points > $team1Points){
119
-                    $team2Points = $team2Points + 1;
120
-                }
121
-                if($team1Points == $team2Points){
122
-                    $team1Points = $team1Points + .5;
123
-                    $team2Points = $team2Points + .5;
124
-                }
125
-            }
126
-
127
-            //Save Points in Teammatches
128
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
129
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
130
-
131
-
132
-        //Need to determine if same amount of scores are in both
133
-        // If not then do not return
134
-
135
-            foreach($team1Scores as $key=>$teamScore){
136
-                if($teamScore <= 0){
137
-                    $team1Scores[$key] = '';
138
-                }
139
-            }
140
-
141
-        foreach($team2Scores as $key=>$teamScore){
142
-            if($teamScore <= 0){
143
-                $team2Scores[$key] = '';
144
-            }
145
-        }
146
-
147
-        $team[0] = [
148
-            "team" =>  $team1Name[0]['name'],
149
-            "hole1" => $team1Scores[0],
150
-            "hole2" => $team1Scores[1],
151
-            "hole3" => $team1Scores[2],
152
-            "hole4" => $team1Scores[3],
153
-            "hole5" => $team1Scores[4],
154
-            "hole6" => $team1Scores[5],
155
-            "hole7" => $team1Scores[6],
156
-            "hole8" => $team1Scores[7],
157
-            "hole9" => $team1Scores[8],
158
-            "points" =>$team1Points
159
-        ];
160
-
161
-        $team[1] = [
162
-            "team" =>  $team2Name[0]['name'],
163
-            "hole1" => $team2Scores[0],
164
-            "hole2" => $team2Scores[1],
165
-            "hole3" => $team2Scores[2],
166
-            "hole4" => $team2Scores[3],
167
-            "hole5" => $team2Scores[4],
168
-            "hole6" => $team2Scores[5],
169
-            "hole7" => $team2Scores[6],
170
-            "hole8" => $team2Scores[7],
171
-            "hole9" => $team2Scores[8],
172
-            "points" => $team2Points
173
-        ];
174
-
175
-        $data['data'] = $team;
176
-        return $data;
90
+		$team1 = array(array_shift ($matchUp));
91
+		$team1Id = $team1[0]['team'];
92
+		$team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
93
+		foreach($matchUp as $key=>$match){
94
+			if($match['team'] == $team1[0]['team']){
95
+				$team1[] = $match;
96
+				unset($matchUp[$key]);
97
+			}
98
+		}
99
+		$team2 = $matchUp;
100
+		$team2Id = $team2[1]['team'];
101
+		$team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray();
102
+
103
+			$holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get();
104
+
105
+			$team1Scores = $this->getTeamNetScore($team1, $holesData);
106
+			$team2Scores = $this->getTeamNetScore($team2, $holesData);
107
+
108
+			$team1Points = $this->calculatePoints($team1Scores, $team2Scores);
109
+			$team2Points = $this->calculatePoints($team2Scores, $team1Scores);
110
+
111
+			// Bonus point logic
112
+			// Occurs after 9th hole score is added to both teams
113
+
114
+			if($team1Scores[8] != null && $team2Scores[8] != null){
115
+				if($team1Points > $team2Points){
116
+					$team1Points = $team1Points + 1;
117
+				}
118
+				if($team2Points > $team1Points){
119
+					$team2Points = $team2Points + 1;
120
+				}
121
+				if($team1Points == $team2Points){
122
+					$team1Points = $team1Points + .5;
123
+					$team2Points = $team2Points + .5;
124
+				}
125
+			}
126
+
127
+			//Save Points in Teammatches
128
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
129
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
130
+
131
+
132
+		//Need to determine if same amount of scores are in both
133
+		// If not then do not return
134
+
135
+			foreach($team1Scores as $key=>$teamScore){
136
+				if($teamScore <= 0){
137
+					$team1Scores[$key] = '';
138
+				}
139
+			}
140
+
141
+		foreach($team2Scores as $key=>$teamScore){
142
+			if($teamScore <= 0){
143
+				$team2Scores[$key] = '';
144
+			}
145
+		}
146
+
147
+		$team[0] = [
148
+			"team" =>  $team1Name[0]['name'],
149
+			"hole1" => $team1Scores[0],
150
+			"hole2" => $team1Scores[1],
151
+			"hole3" => $team1Scores[2],
152
+			"hole4" => $team1Scores[3],
153
+			"hole5" => $team1Scores[4],
154
+			"hole6" => $team1Scores[5],
155
+			"hole7" => $team1Scores[6],
156
+			"hole8" => $team1Scores[7],
157
+			"hole9" => $team1Scores[8],
158
+			"points" =>$team1Points
159
+		];
160
+
161
+		$team[1] = [
162
+			"team" =>  $team2Name[0]['name'],
163
+			"hole1" => $team2Scores[0],
164
+			"hole2" => $team2Scores[1],
165
+			"hole3" => $team2Scores[2],
166
+			"hole4" => $team2Scores[3],
167
+			"hole5" => $team2Scores[4],
168
+			"hole6" => $team2Scores[5],
169
+			"hole7" => $team2Scores[6],
170
+			"hole8" => $team2Scores[7],
171
+			"hole9" => $team2Scores[8],
172
+			"points" => $team2Points
173
+		];
174
+
175
+		$data['data'] = $team;
176
+		return $data;
177 177
 	}
178 178
 
179
-    private function getTeamNetScore($team, $holesData)
180
-    {
181
-        foreach($team as $key=>$item){
182
-            // Create holes array for NET
183
-            $holes = array();
184
-            $i = 1;
185
-            foreach($holesData as $key=>$holeData){
186
-                $holes[$i] = $holeData->handicap;
187
-                $i++;
188
-            }
189
-
190
-            // Create stroke array - how many to take away from score
191
-            $strokeArray = [
192
-                1 => 0,
193
-                2 => 0,
194
-                3 => 0,
195
-                4 => 0,
196
-                5 => 0,
197
-                6 => 0,
198
-                7 => 0,
199
-                8 => 0,
200
-                9 => 0
201
-            ];
202
-            //Create array of strokes
203
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
204
-                if($counter > 9){
205
-                    $newCounter = $counter - 9;
206
-                    while($newCounter > 0) {
207
-                        $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
208
-                        $counter--;
209
-                        $newCounter--;
210
-                    }
211
-                }
212
-                $strokeArray[$counter] = $strokeArray[$counter] + 1;
213
-            }
214
-            // Plus handicaps don't hit previous loop so need its own
215
-            //Plus handicap logic
216
-
217
-            foreach($strokeArray as $strokeKey=>$stroke){
218
-                $holeKey = array_search($strokeKey,$holes);
219
-                $holes[$holeKey] = $stroke;
220
-            }
221
-
222
-            ///now have array of strokes to subtract
223
-            //get array of holescores
224
-
225
-            $holeScores = $item['holescores'];
226
-            foreach($holeScores as $key=>$holeScore){
227
-                //check if new score is less PlayerScores
228
-                if(isset($playerScores[$key])){ // 2nd time in for hole
229
-                    if($playerScores[$key] >= $holeScore['score']){
230
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
231
-                    }
232
-                } else{ // first time in for hole
233
-                    if($holeScore['score'] != null){
234
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
235
-                    } else{
236
-                        $playerScores[$key] = null;
237
-                    }
238
-                }
239
-            }
240
-
241
-        }
242
-        return $playerScores;
243
-    }
244
-
245
-    private function calculatePoints($team, $opponent)
246
-    {
247
-        $points = 0;
248
-        $teamTotalPoints = 0;
249
-        $opponentTotalPoints = 0;
250
-        foreach ($team as $key=>$score){
251
-            if($score != null){
252
-                if($score < $opponent[$key]){
253
-                    $points++;
254
-                }
255
-                if($score == $opponent[$key]){
256
-                    $points = $points + .5;
257
-                }
258
-            }
259
-
260
-        }
261
-
262
-        return $points;
263
-    }
179
+	private function getTeamNetScore($team, $holesData)
180
+	{
181
+		foreach($team as $key=>$item){
182
+			// Create holes array for NET
183
+			$holes = array();
184
+			$i = 1;
185
+			foreach($holesData as $key=>$holeData){
186
+				$holes[$i] = $holeData->handicap;
187
+				$i++;
188
+			}
189
+
190
+			// Create stroke array - how many to take away from score
191
+			$strokeArray = [
192
+				1 => 0,
193
+				2 => 0,
194
+				3 => 0,
195
+				4 => 0,
196
+				5 => 0,
197
+				6 => 0,
198
+				7 => 0,
199
+				8 => 0,
200
+				9 => 0
201
+			];
202
+			//Create array of strokes
203
+			for($counter = $item['matchHandicap']; $counter > 0; $counter--){
204
+				if($counter > 9){
205
+					$newCounter = $counter - 9;
206
+					while($newCounter > 0) {
207
+						$strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
208
+						$counter--;
209
+						$newCounter--;
210
+					}
211
+				}
212
+				$strokeArray[$counter] = $strokeArray[$counter] + 1;
213
+			}
214
+			// Plus handicaps don't hit previous loop so need its own
215
+			//Plus handicap logic
216
+
217
+			foreach($strokeArray as $strokeKey=>$stroke){
218
+				$holeKey = array_search($strokeKey,$holes);
219
+				$holes[$holeKey] = $stroke;
220
+			}
221
+
222
+			///now have array of strokes to subtract
223
+			//get array of holescores
224
+
225
+			$holeScores = $item['holescores'];
226
+			foreach($holeScores as $key=>$holeScore){
227
+				//check if new score is less PlayerScores
228
+				if(isset($playerScores[$key])){ // 2nd time in for hole
229
+					if($playerScores[$key] >= $holeScore['score']){
230
+						$playerScores[$key] = $holeScore['score'] - $holes[$key+1];
231
+					}
232
+				} else{ // first time in for hole
233
+					if($holeScore['score'] != null){
234
+						$playerScores[$key] = $holeScore['score'] - $holes[$key+1];
235
+					} else{
236
+						$playerScores[$key] = null;
237
+					}
238
+				}
239
+			}
240
+
241
+		}
242
+		return $playerScores;
243
+	}
244
+
245
+	private function calculatePoints($team, $opponent)
246
+	{
247
+		$points = 0;
248
+		$teamTotalPoints = 0;
249
+		$opponentTotalPoints = 0;
250
+		foreach ($team as $key=>$score){
251
+			if($score != null){
252
+				if($score < $opponent[$key]){
253
+					$points++;
254
+				}
255
+				if($score == $opponent[$key]){
256
+					$points = $points + .5;
257
+				}
258
+			}
259
+
260
+		}
261
+
262
+		return $points;
263
+	}
264 264
 
265 265
 	/**
266 266
 	 * Show the form for editing the specified resource.
@@ -298,15 +298,15 @@  discard block
 block discarded – undo
298 298
 	}
299 299
 
300 300
 	public function getPointsByYear($year)
301
-    {
302
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
303
-        foreach ($teamMatches as $key=>$teamMatch) {
304
-            $pointsData[$key]['name'] = $teamMatch['team']['name'];
305
-            $pointsData[$key]['points'] = $teamMatch['pointsWon'];
306
-        }
307
-        $data['data'] = $pointsData;
308
-        return $data;
309
-    }
301
+	{
302
+		$teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
303
+		foreach ($teamMatches as $key=>$teamMatch) {
304
+			$pointsData[$key]['name'] = $teamMatch['team']['name'];
305
+			$pointsData[$key]['points'] = $teamMatch['pointsWon'];
306
+		}
307
+		$data['data'] = $pointsData;
308
+		return $data;
309
+	}
310 310
 
311 311
 
312 312
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
         //Create Player data
65 65
         $matchUp = array();
66
-        foreach($groupPlayers as $key=>$groupPlayer){
66
+        foreach ($groupPlayers as $key=>$groupPlayer) {
67 67
             $matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68
-            $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
-            foreach ($groupPlayer->round as $round){
68
+            $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap, 0);
69
+            foreach ($groupPlayer->round as $round) {
70 70
                 $matchUp[$key]['team'] = $round->team_id;
71 71
                 $matchUp[$key]['course'] = $round->course_id;
72 72
                 $matchUp[$key]['holescores'] = $round->holescores;
@@ -75,23 +75,23 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         // Change lowest handicap to ZERO and change others to reflect it
78
-            foreach($matchUp as $key=>$match){
78
+            foreach ($matchUp as $key=>$match) {
79 79
                 $matchHandicaps[] = $match['matchHandicap'];
80 80
             }
81 81
             $lowestMatchHandicap = min($matchHandicaps);
82 82
             //handicap change
83 83
             $handicapChange = $lowestMatchHandicap * -1;
84
-            foreach($matchUp as $key=>$match){
84
+            foreach ($matchUp as $key=>$match) {
85 85
                 $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86 86
             }
87 87
 
88 88
 
89 89
 // Separate two teams
90
-        $team1 = array(array_shift ($matchUp));
90
+        $team1 = array(array_shift($matchUp));
91 91
         $team1Id = $team1[0]['team'];
92 92
         $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
93
-        foreach($matchUp as $key=>$match){
94
-            if($match['team'] == $team1[0]['team']){
93
+        foreach ($matchUp as $key=>$match) {
94
+            if ($match['team'] == $team1[0]['team']) {
95 95
                 $team1[] = $match;
96 96
                 unset($matchUp[$key]);
97 97
             }
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
             // Bonus point logic
112 112
             // Occurs after 9th hole score is added to both teams
113 113
 
114
-            if($team1Scores[8] != null && $team2Scores[8] != null){
115
-                if($team1Points > $team2Points){
114
+            if ($team1Scores[8] != null && $team2Scores[8] != null) {
115
+                if ($team1Points > $team2Points) {
116 116
                     $team1Points = $team1Points + 1;
117 117
                 }
118
-                if($team2Points > $team1Points){
118
+                if ($team2Points > $team1Points) {
119 119
                     $team2Points = $team2Points + 1;
120 120
                 }
121
-                if($team1Points == $team2Points){
121
+                if ($team1Points == $team2Points) {
122 122
                     $team1Points = $team1Points + .5;
123 123
                     $team2Points = $team2Points + .5;
124 124
                 }
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
         //Need to determine if same amount of scores are in both
133 133
         // If not then do not return
134 134
 
135
-            foreach($team1Scores as $key=>$teamScore){
136
-                if($teamScore <= 0){
135
+            foreach ($team1Scores as $key=>$teamScore) {
136
+                if ($teamScore <= 0) {
137 137
                     $team1Scores[$key] = '';
138 138
                 }
139 139
             }
140 140
 
141
-        foreach($team2Scores as $key=>$teamScore){
142
-            if($teamScore <= 0){
141
+        foreach ($team2Scores as $key=>$teamScore) {
142
+            if ($teamScore <= 0) {
143 143
                 $team2Scores[$key] = '';
144 144
             }
145 145
         }
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 
179 179
     private function getTeamNetScore($team, $holesData)
180 180
     {
181
-        foreach($team as $key=>$item){
181
+        foreach ($team as $key=>$item) {
182 182
             // Create holes array for NET
183 183
             $holes = array();
184 184
             $i = 1;
185
-            foreach($holesData as $key=>$holeData){
185
+            foreach ($holesData as $key=>$holeData) {
186 186
                 $holes[$i] = $holeData->handicap;
187 187
                 $i++;
188 188
             }
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
                 9 => 0
201 201
             ];
202 202
             //Create array of strokes
203
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
204
-                if($counter > 9){
203
+            for ($counter = $item['matchHandicap']; $counter > 0; $counter--) {
204
+                if ($counter > 9) {
205 205
                     $newCounter = $counter - 9;
206
-                    while($newCounter > 0) {
206
+                    while ($newCounter > 0) {
207 207
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
208 208
                         $counter--;
209 209
                         $newCounter--;
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
             // Plus handicaps don't hit previous loop so need its own
215 215
             //Plus handicap logic
216 216
 
217
-            foreach($strokeArray as $strokeKey=>$stroke){
218
-                $holeKey = array_search($strokeKey,$holes);
217
+            foreach ($strokeArray as $strokeKey=>$stroke) {
218
+                $holeKey = array_search($strokeKey, $holes);
219 219
                 $holes[$holeKey] = $stroke;
220 220
             }
221 221
 
@@ -223,16 +223,16 @@  discard block
 block discarded – undo
223 223
             //get array of holescores
224 224
 
225 225
             $holeScores = $item['holescores'];
226
-            foreach($holeScores as $key=>$holeScore){
226
+            foreach ($holeScores as $key=>$holeScore) {
227 227
                 //check if new score is less PlayerScores
228
-                if(isset($playerScores[$key])){ // 2nd time in for hole
229
-                    if($playerScores[$key] >= $holeScore['score']){
230
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
228
+                if (isset($playerScores[$key])) { // 2nd time in for hole
229
+                    if ($playerScores[$key] >= $holeScore['score']) {
230
+                        $playerScores[$key] = $holeScore['score'] - $holes[$key + 1];
231 231
                     }
232
-                } else{ // first time in for hole
233
-                    if($holeScore['score'] != null){
234
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
235
-                    } else{
232
+                } else { // first time in for hole
233
+                    if ($holeScore['score'] != null) {
234
+                        $playerScores[$key] = $holeScore['score'] - $holes[$key + 1];
235
+                    } else {
236 236
                         $playerScores[$key] = null;
237 237
                     }
238 238
                 }
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
         $points = 0;
248 248
         $teamTotalPoints = 0;
249 249
         $opponentTotalPoints = 0;
250
-        foreach ($team as $key=>$score){
251
-            if($score != null){
252
-                if($score < $opponent[$key]){
250
+        foreach ($team as $key=>$score) {
251
+            if ($score != null) {
252
+                if ($score < $opponent[$key]) {
253 253
                     $points++;
254 254
                 }
255
-                if($score == $opponent[$key]){
255
+                if ($score == $opponent[$key]) {
256 256
                     $points = $points + .5;
257 257
                 }
258 258
             }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 
300 300
 	public function getPointsByYear($year)
301 301
     {
302
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
302
+        $teamMatches = Teammatch::select('team_id', 'pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
303 303
         foreach ($teamMatches as $key=>$teamMatch) {
304 304
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
305 305
             $pointsData[$key]['points'] = $teamMatch['pointsWon'];
Please login to merge, or discard this patch.
Braces   +32 added lines, -30 removed lines patch added patch discarded remove patch
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
         //Create Player data
65 65
         $matchUp = array();
66
-        foreach($groupPlayers as $key=>$groupPlayer){
66
+        foreach($groupPlayers as $key=>$groupPlayer) {
67 67
             $matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68 68
             $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
-            foreach ($groupPlayer->round as $round){
69
+            foreach ($groupPlayer->round as $round) {
70 70
                 $matchUp[$key]['team'] = $round->team_id;
71 71
                 $matchUp[$key]['course'] = $round->course_id;
72 72
                 $matchUp[$key]['holescores'] = $round->holescores;
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         // Change lowest handicap to ZERO and change others to reflect it
78
-            foreach($matchUp as $key=>$match){
78
+            foreach($matchUp as $key=>$match) {
79 79
                 $matchHandicaps[] = $match['matchHandicap'];
80 80
             }
81 81
             $lowestMatchHandicap = min($matchHandicaps);
82 82
             //handicap change
83 83
             $handicapChange = $lowestMatchHandicap * -1;
84
-            foreach($matchUp as $key=>$match){
84
+            foreach($matchUp as $key=>$match) {
85 85
                 $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86 86
             }
87 87
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
         $team1 = array(array_shift ($matchUp));
91 91
         $team1Id = $team1[0]['team'];
92 92
         $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
93
-        foreach($matchUp as $key=>$match){
94
-            if($match['team'] == $team1[0]['team']){
93
+        foreach($matchUp as $key=>$match) {
94
+            if($match['team'] == $team1[0]['team']) {
95 95
                 $team1[] = $match;
96 96
                 unset($matchUp[$key]);
97 97
             }
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
             // Bonus point logic
112 112
             // Occurs after 9th hole score is added to both teams
113 113
 
114
-            if($team1Scores[8] != null && $team2Scores[8] != null){
115
-                if($team1Points > $team2Points){
114
+            if($team1Scores[8] != null && $team2Scores[8] != null) {
115
+                if($team1Points > $team2Points) {
116 116
                     $team1Points = $team1Points + 1;
117 117
                 }
118
-                if($team2Points > $team1Points){
118
+                if($team2Points > $team1Points) {
119 119
                     $team2Points = $team2Points + 1;
120 120
                 }
121
-                if($team1Points == $team2Points){
121
+                if($team1Points == $team2Points) {
122 122
                     $team1Points = $team1Points + .5;
123 123
                     $team2Points = $team2Points + .5;
124 124
                 }
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
         //Need to determine if same amount of scores are in both
133 133
         // If not then do not return
134 134
 
135
-            foreach($team1Scores as $key=>$teamScore){
136
-                if($teamScore <= 0){
135
+            foreach($team1Scores as $key=>$teamScore) {
136
+                if($teamScore <= 0) {
137 137
                     $team1Scores[$key] = '';
138 138
                 }
139 139
             }
140 140
 
141
-        foreach($team2Scores as $key=>$teamScore){
142
-            if($teamScore <= 0){
141
+        foreach($team2Scores as $key=>$teamScore) {
142
+            if($teamScore <= 0) {
143 143
                 $team2Scores[$key] = '';
144 144
             }
145 145
         }
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 
179 179
     private function getTeamNetScore($team, $holesData)
180 180
     {
181
-        foreach($team as $key=>$item){
181
+        foreach($team as $key=>$item) {
182 182
             // Create holes array for NET
183 183
             $holes = array();
184 184
             $i = 1;
185
-            foreach($holesData as $key=>$holeData){
185
+            foreach($holesData as $key=>$holeData) {
186 186
                 $holes[$i] = $holeData->handicap;
187 187
                 $i++;
188 188
             }
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
                 9 => 0
201 201
             ];
202 202
             //Create array of strokes
203
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
204
-                if($counter > 9){
203
+            for($counter = $item['matchHandicap']; $counter > 0; $counter--) {
204
+                if($counter > 9) {
205 205
                     $newCounter = $counter - 9;
206 206
                     while($newCounter > 0) {
207 207
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
             // Plus handicaps don't hit previous loop so need its own
215 215
             //Plus handicap logic
216 216
 
217
-            foreach($strokeArray as $strokeKey=>$stroke){
217
+            foreach($strokeArray as $strokeKey=>$stroke) {
218 218
                 $holeKey = array_search($strokeKey,$holes);
219 219
                 $holes[$holeKey] = $stroke;
220 220
             }
@@ -223,16 +223,18 @@  discard block
 block discarded – undo
223 223
             //get array of holescores
224 224
 
225 225
             $holeScores = $item['holescores'];
226
-            foreach($holeScores as $key=>$holeScore){
226
+            foreach($holeScores as $key=>$holeScore) {
227 227
                 //check if new score is less PlayerScores
228
-                if(isset($playerScores[$key])){ // 2nd time in for hole
229
-                    if($playerScores[$key] >= $holeScore['score']){
228
+                if(isset($playerScores[$key])) {
229
+// 2nd time in for hole
230
+                    if($playerScores[$key] >= $holeScore['score']) {
230 231
                         $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
231 232
                     }
232
-                } else{ // first time in for hole
233
-                    if($holeScore['score'] != null){
233
+                } else {
234
+// first time in for hole
235
+                    if($holeScore['score'] != null) {
234 236
                         $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
235
-                    } else{
237
+                    } else {
236 238
                         $playerScores[$key] = null;
237 239
                     }
238 240
                 }
@@ -247,12 +249,12 @@  discard block
 block discarded – undo
247 249
         $points = 0;
248 250
         $teamTotalPoints = 0;
249 251
         $opponentTotalPoints = 0;
250
-        foreach ($team as $key=>$score){
251
-            if($score != null){
252
-                if($score < $opponent[$key]){
252
+        foreach ($team as $key=>$score) {
253
+            if($score != null) {
254
+                if($score < $opponent[$key]) {
253 255
                     $points++;
254 256
                 }
255
-                if($score == $opponent[$key]){
257
+                if($score == $opponent[$key]) {
256 258
                     $points = $points + .5;
257 259
                 }
258 260
             }
@@ -298,7 +300,7 @@  discard block
 block discarded – undo
298 300
 	}
299 301
 
300 302
 	public function getPointsByYear($year)
301
-    {
303
+	{
302 304
         $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
303 305
         foreach ($teamMatches as $key=>$teamMatch) {
304 306
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
Please login to merge, or discard this patch.