Completed
Push — master ( c2b49a...8bd31d )
by Michael
02:56
created
app/controllers/TeamMatchesController.php 1 patch
Spacing   +35 added lines, -35 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,22 +75,22 @@  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
         // Separate two teams
89
-            $team1 = array(array_shift ($matchUp));
89
+            $team1 = array(array_shift($matchUp));
90 90
             $team1Id = $team1[0]['team'];
91 91
             $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
92
-            foreach($matchUp as $key=>$match){
93
-                if($match['team'] == $team1[0]['team']){
92
+            foreach ($matchUp as $key=>$match) {
93
+                if ($match['team'] == $team1[0]['team']) {
94 94
                     $team1[] = $match;
95 95
                     unset($matchUp[$key]);
96 96
                 }
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
         //Need to determine if same amount of scores are in both
116 116
         // If not then do not return
117 117
 
118
-            foreach($team1Scores as $key=>$teamScore){
119
-                if($teamScore <= 0){
118
+            foreach ($team1Scores as $key=>$teamScore) {
119
+                if ($teamScore <= 0) {
120 120
                     $team1Scores[$key] = '';
121 121
                 }
122 122
             }
123 123
 
124
-        foreach($team2Scores as $key=>$teamScore){
125
-            if($teamScore <= 0){
124
+        foreach ($team2Scores as $key=>$teamScore) {
125
+            if ($teamScore <= 0) {
126 126
                 $team2Scores[$key] = '';
127 127
             }
128 128
         }
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 
162 162
     private function getTeamNetScore($team, $holesData)
163 163
     {
164
-        foreach($team as $key=>$item){
164
+        foreach ($team as $key=>$item) {
165 165
             // Create holes array for NET
166 166
             $holes = array();
167 167
             $i = 1;
168
-            foreach($holesData as $key=>$holeData){
168
+            foreach ($holesData as $key=>$holeData) {
169 169
                 $holes[$i] = $holeData->handicap;
170 170
                 $i++;
171 171
             }
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
                 9 => 0
184 184
             ];
185 185
             //Create array of strokes
186
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
187
-                if($counter > 9){
186
+            for ($counter = $item['matchHandicap']; $counter > 0; $counter--) {
187
+                if ($counter > 9) {
188 188
                     $newCounter = $counter - 9;
189
-                    while($newCounter > 0) {
189
+                    while ($newCounter > 0) {
190 190
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
191 191
                         $counter--;
192 192
                         $newCounter--;
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
             // Plus handicaps don't hit previous loop so need its own
198 198
             //Plus handicap logic
199 199
 
200
-            foreach($strokeArray as $strokeKey=>$stroke){
201
-                $holeKey = array_search($strokeKey,$holes);
200
+            foreach ($strokeArray as $strokeKey=>$stroke) {
201
+                $holeKey = array_search($strokeKey, $holes);
202 202
                 $holes[$holeKey] = $stroke;
203 203
             }
204 204
 
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
             //get array of holescores
207 207
 
208 208
             $holeScores = $item['holescores'];
209
-            foreach($holeScores as $key=>$holeScore){
209
+            foreach ($holeScores as $key=>$holeScore) {
210 210
                 //check if new score is less PlayerScores
211
-                if(isset($playerScores[$key])){ // 2nd time in for hole
212
-                    if($playerScores[$key] >= $holeScore['score']){
213
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
211
+                if (isset($playerScores[$key])) { // 2nd time in for hole
212
+                    if ($playerScores[$key] >= $holeScore['score']) {
213
+                        $playerScores[$key] = $holeScore['score'] - $holes[$key + 1];
214 214
                     }
215
-                } else{ // first time in for hole
216
-                    if($holeScore['score'] != null){
217
-                        $playerScores[$key] = $holeScore['score'] - $holes[$key+1];
218
-                    } else{
215
+                } else { // first time in for hole
216
+                    if ($holeScore['score'] != null) {
217
+                        $playerScores[$key] = $holeScore['score'] - $holes[$key + 1];
218
+                    } else {
219 219
                         $playerScores[$key] = null;
220 220
                     }
221 221
                 }
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
         $points = 0;
231 231
         $teamTotalPoints = 0;
232 232
         $opponentTotalPoints = 0;
233
-        foreach ($team as $key=>$score){
234
-            if($score != null){
235
-                if($score < $opponent[$key]){
233
+        foreach ($team as $key=>$score) {
234
+            if ($score != null) {
235
+                if ($score < $opponent[$key]) {
236 236
                     $points++;
237 237
                 }
238
-                if($score == $opponent[$key]){
238
+                if ($score == $opponent[$key]) {
239 239
                     $points = $points + .5;
240 240
                 }
241 241
             }
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
             $opponentTotalPoints = $opponentTotalPoints + $points;
244 244
         }
245 245
         // Bonus point logic
246
-        if($team[8] != null && $opponent[8] != null){
247
-            if($teamTotalPoints > $opponentTotalPoints){
246
+        if ($team[8] != null && $opponent[8] != null) {
247
+            if ($teamTotalPoints > $opponentTotalPoints) {
248 248
                 $points = $points + 1;
249 249
             }
250
-            if($teamTotalPoints == $opponentTotalPoints){
250
+            if ($teamTotalPoints == $opponentTotalPoints) {
251 251
                 $points = $points + .5;
252 252
             }
253 253
         }
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 
292 292
 	public function getPointsByYear($year)
293 293
     {
294
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
294
+        $teamMatches = Teammatch::select('team_id', 'pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
295 295
         foreach ($teamMatches as $key=>$teamMatch) {
296 296
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
297 297
             $pointsData[$key]['points'] = $teamMatch['pointsWon'];
Please login to merge, or discard this patch.