Completed
Push — master ( 7e18a1...a2fd09 )
by Michael
03:09
created
app/library/Handlers/FinalizeHandler.php 3 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -18,130 +18,130 @@
 block discarded – undo
18 18
  */
19 19
 class FinalizeHandler
20 20
 {
21
-    /**
22
-     * Create a new instance of the MatchHandler
23
-     *
24
-     * @param  GolfLeague\Storage\Round\RoundRepository $roundRepo
25
-     * @return void
26
-     */
27
-    public function __construct(RoundRepository $roundRepo)
28
-    {
29
-        $this->roundRepo= $roundRepo;
30
-    } // End of __construct
21
+	/**
22
+	 * Create a new instance of the MatchHandler
23
+	 *
24
+	 * @param  GolfLeague\Storage\Round\RoundRepository $roundRepo
25
+	 * @return void
26
+	 */
27
+	public function __construct(RoundRepository $roundRepo)
28
+	{
29
+		$this->roundRepo= $roundRepo;
30
+	} // End of __construct
31 31
 
32
-    /**
33
-     * Create an initial round for each player after a new match is created
34
-     *
35
-     * @param  Match $match
36
-     * @return void
37
-     */
38
-    public function handle($match)
39
-    {
40
-        //for the match get ctps, netwinner, grosswinner, and skins
41
-        //calculate winnings
42
-        //store in the pivot table match_player for the given player
32
+	/**
33
+	 * Create an initial round for each player after a new match is created
34
+	 *
35
+	 * @param  Match $match
36
+	 * @return void
37
+	 */
38
+	public function handle($match)
39
+	{
40
+		//for the match get ctps, netwinner, grosswinner, and skins
41
+		//calculate winnings
42
+		//store in the pivot table match_player for the given player
43 43
 
44
-        $winningPlayers = array();
45
-        $i = 1;
44
+		$winningPlayers = array();
45
+		$i = 1;
46 46
 
47
-        $ctpWinners = Ctp::where('match_id', '=', $match->id)->get();
48
-        foreach($ctpWinners as $key => $ctpWinner){
49
-            $playerExists = $this->recursive_array_search($ctpWinner->player_id, $winningPlayers);
50
-            //if player is already there add money here to other money
51
-            if($playerExists){
52
-                $winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
53
-                $winningPlayers[$i]['money'] = ($ctpWinner->money + $winningPlayers[$playerExists]['money']);
54
-                unset($winningPlayers[$playerExists]);
55
-            }
56
-            else {
57
-                $winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
58
-                $winningPlayers[$i]['money'] = $ctpWinner->money;
59
-            }
60
-            $i++;
61
-        }
47
+		$ctpWinners = Ctp::where('match_id', '=', $match->id)->get();
48
+		foreach($ctpWinners as $key => $ctpWinner){
49
+			$playerExists = $this->recursive_array_search($ctpWinner->player_id, $winningPlayers);
50
+			//if player is already there add money here to other money
51
+			if($playerExists){
52
+				$winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
53
+				$winningPlayers[$i]['money'] = ($ctpWinner->money + $winningPlayers[$playerExists]['money']);
54
+				unset($winningPlayers[$playerExists]);
55
+			}
56
+			else {
57
+				$winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
58
+				$winningPlayers[$i]['money'] = $ctpWinner->money;
59
+			}
60
+			$i++;
61
+		}
62 62
 
63
-        $netWinners = Netwinner::where('match_id', '=', $match->id)->get();
64
-        foreach($netWinners as $key => $netWinner){
65
-            $playerExists = $this->recursive_array_search($netWinner->player_id, $winningPlayers);
66
-            //if player is already there add money here to other money
67
-            if($playerExists){
68
-                $winningPlayers[$i]['player_id'] = $netWinner->player_id;
69
-                $winningPlayers[$i]['money'] = ($netWinner->money + $winningPlayers[$playerExists]['money']);
70
-                unset($winningPlayers[$playerExists]);
71
-            }
72
-            else{
73
-                $winningPlayers[$i]['player_id'] = $netWinner->player_id;
74
-                $winningPlayers[$i]['money'] = $netWinner->money;
75
-            }
76
-            $i++;
77
-        }
63
+		$netWinners = Netwinner::where('match_id', '=', $match->id)->get();
64
+		foreach($netWinners as $key => $netWinner){
65
+			$playerExists = $this->recursive_array_search($netWinner->player_id, $winningPlayers);
66
+			//if player is already there add money here to other money
67
+			if($playerExists){
68
+				$winningPlayers[$i]['player_id'] = $netWinner->player_id;
69
+				$winningPlayers[$i]['money'] = ($netWinner->money + $winningPlayers[$playerExists]['money']);
70
+				unset($winningPlayers[$playerExists]);
71
+			}
72
+			else{
73
+				$winningPlayers[$i]['player_id'] = $netWinner->player_id;
74
+				$winningPlayers[$i]['money'] = $netWinner->money;
75
+			}
76
+			$i++;
77
+		}
78 78
 
79
-        $grossWinners = Grosswinner::where('match_id', '=', $match->id)->get();
80
-        foreach($grossWinners as $key => $grossWinner){
81
-            $playerExists = $this->recursive_array_search($grossWinner->player_id, $winningPlayers);
82
-            //if player is already there add money here to other money
83
-            if($playerExists){
84
-                $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
85
-                $winningPlayers[$i]['money'] = ($grossWinner->money + $winningPlayers[$playerExists]['money']);
86
-                unset($winningPlayers[$playerExists]);
87
-            }
88
-            else{
89
-                $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
90
-                $winningPlayers[$i]['money'] = $grossWinner->money;
91
-            }
92
-            $i++;
93
-        }
79
+		$grossWinners = Grosswinner::where('match_id', '=', $match->id)->get();
80
+		foreach($grossWinners as $key => $grossWinner){
81
+			$playerExists = $this->recursive_array_search($grossWinner->player_id, $winningPlayers);
82
+			//if player is already there add money here to other money
83
+			if($playerExists){
84
+				$winningPlayers[$i]['player_id'] = $grossWinner->player_id;
85
+				$winningPlayers[$i]['money'] = ($grossWinner->money + $winningPlayers[$playerExists]['money']);
86
+				unset($winningPlayers[$playerExists]);
87
+			}
88
+			else{
89
+				$winningPlayers[$i]['player_id'] = $grossWinner->player_id;
90
+				$winningPlayers[$i]['money'] = $grossWinner->money;
91
+			}
92
+			$i++;
93
+		}
94 94
 
95
-        $skinWinners = Skin::where('match_id', '=', $match->id)->get();
96
-        foreach($skinWinners as $key => $skinWinner){
97
-            $playerExists = $this->recursive_array_search($skinWinner->player_id, $winningPlayers);
98
-            //if player is already there add money here to other money
99
-            if($playerExists){
100
-                $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
101
-                $winningPlayers[$i]['money'] = ($skinWinner->money + $winningPlayers[$playerExists]['money']);
102
-                unset($winningPlayers[$playerExists]);
103
-            }
104
-            else{
105
-                $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
106
-                $winningPlayers[$i]['money'] = $skinWinner->money;
107
-            }
108
-            $i++;
109
-        }
95
+		$skinWinners = Skin::where('match_id', '=', $match->id)->get();
96
+		foreach($skinWinners as $key => $skinWinner){
97
+			$playerExists = $this->recursive_array_search($skinWinner->player_id, $winningPlayers);
98
+			//if player is already there add money here to other money
99
+			if($playerExists){
100
+				$winningPlayers[$i]['player_id'] = $skinWinner->player_id;
101
+				$winningPlayers[$i]['money'] = ($skinWinner->money + $winningPlayers[$playerExists]['money']);
102
+				unset($winningPlayers[$playerExists]);
103
+			}
104
+			else{
105
+				$winningPlayers[$i]['player_id'] = $skinWinner->player_id;
106
+				$winningPlayers[$i]['money'] = $skinWinner->money;
107
+			}
108
+			$i++;
109
+		}
110 110
 
111
-        //Consolidate any multiple instances of a player
112
-        foreach ($winningPlayers as $key => $winningPlayer){
113
-            array_search($winningPlayer['player_id'], $winningPlayers);
114
-        }
111
+		//Consolidate any multiple instances of a player
112
+		foreach ($winningPlayers as $key => $winningPlayer){
113
+			array_search($winningPlayer['player_id'], $winningPlayers);
114
+		}
115 115
 
116
-        foreach ($winningPlayers as $key => $player){
117
-            $currentPlayer = Player::find($player['player_id']);
118
-            $attributes = array(
119
-                "winnings" => $player['money']
120
-            );
121
-            $currentPlayer->matches()->updateExistingPivot($match->id, $attributes); //save match_player pivot data
122
-        }// End foreach
116
+		foreach ($winningPlayers as $key => $player){
117
+			$currentPlayer = Player::find($player['player_id']);
118
+			$attributes = array(
119
+				"winnings" => $player['money']
120
+			);
121
+			$currentPlayer->matches()->updateExistingPivot($match->id, $attributes); //save match_player pivot data
122
+		}// End foreach
123 123
 
124 124
 
125
-    }
125
+	}
126 126
 
127
-    /**
128
-     * Register the listeners for the subscriber.
129
-     *
130
-     * @param  Illuminate\Events\Dispatcher $events
131
-     * @return array
132
-     */
133
-    public function subscribe($events)
134
-    {
135
-        $events->listen('match.finalize', 'GolfLeague\Handlers\FinalizeHandler');
136
-    }
127
+	/**
128
+	 * Register the listeners for the subscriber.
129
+	 *
130
+	 * @param  Illuminate\Events\Dispatcher $events
131
+	 * @return array
132
+	 */
133
+	public function subscribe($events)
134
+	{
135
+		$events->listen('match.finalize', 'GolfLeague\Handlers\FinalizeHandler');
136
+	}
137 137
 
138
-    public function recursive_array_search($needle,$haystack) {
139
-        foreach($haystack as $key=>$value) {
140
-            $current_key=$key;
141
-            if($needle===$value || (is_array($value) && $this->recursive_array_search($needle,$value) !== false)) {
142
-                return $current_key;
143
-            }
144
-        }
145
-        return false;
146
-    }
138
+	public function recursive_array_search($needle,$haystack) {
139
+		foreach($haystack as $key=>$value) {
140
+			$current_key=$key;
141
+			if($needle===$value || (is_array($value) && $this->recursive_array_search($needle,$value) !== false)) {
142
+				return $current_key;
143
+			}
144
+		}
145
+		return false;
146
+	}
147 147
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct(RoundRepository $roundRepo)
28 28
     {
29
-        $this->roundRepo= $roundRepo;
29
+        $this->roundRepo = $roundRepo;
30 30
     } // End of __construct
31 31
 
32 32
     /**
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
         $i = 1;
46 46
 
47 47
         $ctpWinners = Ctp::where('match_id', '=', $match->id)->get();
48
-        foreach($ctpWinners as $key => $ctpWinner){
48
+        foreach ($ctpWinners as $key => $ctpWinner) {
49 49
             $playerExists = $this->recursive_array_search($ctpWinner->player_id, $winningPlayers);
50 50
             //if player is already there add money here to other money
51
-            if($playerExists){
51
+            if ($playerExists) {
52 52
                 $winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
53 53
                 $winningPlayers[$i]['money'] = ($ctpWinner->money + $winningPlayers[$playerExists]['money']);
54 54
                 unset($winningPlayers[$playerExists]);
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
         }
62 62
 
63 63
         $netWinners = Netwinner::where('match_id', '=', $match->id)->get();
64
-        foreach($netWinners as $key => $netWinner){
64
+        foreach ($netWinners as $key => $netWinner) {
65 65
             $playerExists = $this->recursive_array_search($netWinner->player_id, $winningPlayers);
66 66
             //if player is already there add money here to other money
67
-            if($playerExists){
67
+            if ($playerExists) {
68 68
                 $winningPlayers[$i]['player_id'] = $netWinner->player_id;
69 69
                 $winningPlayers[$i]['money'] = ($netWinner->money + $winningPlayers[$playerExists]['money']);
70 70
                 unset($winningPlayers[$playerExists]);
71 71
             }
72
-            else{
72
+            else {
73 73
                 $winningPlayers[$i]['player_id'] = $netWinner->player_id;
74 74
                 $winningPlayers[$i]['money'] = $netWinner->money;
75 75
             }
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
         }
78 78
 
79 79
         $grossWinners = Grosswinner::where('match_id', '=', $match->id)->get();
80
-        foreach($grossWinners as $key => $grossWinner){
80
+        foreach ($grossWinners as $key => $grossWinner) {
81 81
             $playerExists = $this->recursive_array_search($grossWinner->player_id, $winningPlayers);
82 82
             //if player is already there add money here to other money
83
-            if($playerExists){
83
+            if ($playerExists) {
84 84
                 $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
85 85
                 $winningPlayers[$i]['money'] = ($grossWinner->money + $winningPlayers[$playerExists]['money']);
86 86
                 unset($winningPlayers[$playerExists]);
87 87
             }
88
-            else{
88
+            else {
89 89
                 $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
90 90
                 $winningPlayers[$i]['money'] = $grossWinner->money;
91 91
             }
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
         }
94 94
 
95 95
         $skinWinners = Skin::where('match_id', '=', $match->id)->get();
96
-        foreach($skinWinners as $key => $skinWinner){
96
+        foreach ($skinWinners as $key => $skinWinner) {
97 97
             $playerExists = $this->recursive_array_search($skinWinner->player_id, $winningPlayers);
98 98
             //if player is already there add money here to other money
99
-            if($playerExists){
99
+            if ($playerExists) {
100 100
                 $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
101 101
                 $winningPlayers[$i]['money'] = ($skinWinner->money + $winningPlayers[$playerExists]['money']);
102 102
                 unset($winningPlayers[$playerExists]);
103 103
             }
104
-            else{
104
+            else {
105 105
                 $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
106 106
                 $winningPlayers[$i]['money'] = $skinWinner->money;
107 107
             }
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
         }
110 110
 
111 111
         //Consolidate any multiple instances of a player
112
-        foreach ($winningPlayers as $key => $winningPlayer){
112
+        foreach ($winningPlayers as $key => $winningPlayer) {
113 113
             array_search($winningPlayer['player_id'], $winningPlayers);
114 114
         }
115 115
 
116
-        foreach ($winningPlayers as $key => $player){
116
+        foreach ($winningPlayers as $key => $player) {
117 117
             $currentPlayer = Player::find($player['player_id']);
118 118
             $attributes = array(
119 119
                 "winnings" => $player['money']
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
         $events->listen('match.finalize', 'GolfLeague\Handlers\FinalizeHandler');
136 136
     }
137 137
 
138
-    public function recursive_array_search($needle,$haystack) {
139
-        foreach($haystack as $key=>$value) {
140
-            $current_key=$key;
141
-            if($needle===$value || (is_array($value) && $this->recursive_array_search($needle,$value) !== false)) {
138
+    public function recursive_array_search($needle, $haystack) {
139
+        foreach ($haystack as $key=>$value) {
140
+            $current_key = $key;
141
+            if ($needle === $value || (is_array($value) && $this->recursive_array_search($needle, $value) !== false)) {
142 142
                 return $current_key;
143 143
             }
144 144
         }
Please login to merge, or discard this patch.
Braces   +17 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@  discard block
 block discarded – undo
16 16
  *
17 17
  * @author          Michael Schmidt
18 18
  */
19
-class FinalizeHandler
20
-{
19
+class FinalizeHandler {
21 20
     /**
22 21
      * Create a new instance of the MatchHandler
23 22
      *
@@ -45,15 +44,14 @@  discard block
 block discarded – undo
45 44
         $i = 1;
46 45
 
47 46
         $ctpWinners = Ctp::where('match_id', '=', $match->id)->get();
48
-        foreach($ctpWinners as $key => $ctpWinner){
47
+        foreach($ctpWinners as $key => $ctpWinner) {
49 48
             $playerExists = $this->recursive_array_search($ctpWinner->player_id, $winningPlayers);
50 49
             //if player is already there add money here to other money
51
-            if($playerExists){
50
+            if($playerExists) {
52 51
                 $winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
53 52
                 $winningPlayers[$i]['money'] = ($ctpWinner->money + $winningPlayers[$playerExists]['money']);
54 53
                 unset($winningPlayers[$playerExists]);
55
-            }
56
-            else {
54
+            } else {
57 55
                 $winningPlayers[$i]['player_id'] = $ctpWinner->player_id;
58 56
                 $winningPlayers[$i]['money'] = $ctpWinner->money;
59 57
             }
@@ -61,15 +59,14 @@  discard block
 block discarded – undo
61 59
         }
62 60
 
63 61
         $netWinners = Netwinner::where('match_id', '=', $match->id)->get();
64
-        foreach($netWinners as $key => $netWinner){
62
+        foreach($netWinners as $key => $netWinner) {
65 63
             $playerExists = $this->recursive_array_search($netWinner->player_id, $winningPlayers);
66 64
             //if player is already there add money here to other money
67
-            if($playerExists){
65
+            if($playerExists) {
68 66
                 $winningPlayers[$i]['player_id'] = $netWinner->player_id;
69 67
                 $winningPlayers[$i]['money'] = ($netWinner->money + $winningPlayers[$playerExists]['money']);
70 68
                 unset($winningPlayers[$playerExists]);
71
-            }
72
-            else{
69
+            } else {
73 70
                 $winningPlayers[$i]['player_id'] = $netWinner->player_id;
74 71
                 $winningPlayers[$i]['money'] = $netWinner->money;
75 72
             }
@@ -77,15 +74,14 @@  discard block
 block discarded – undo
77 74
         }
78 75
 
79 76
         $grossWinners = Grosswinner::where('match_id', '=', $match->id)->get();
80
-        foreach($grossWinners as $key => $grossWinner){
77
+        foreach($grossWinners as $key => $grossWinner) {
81 78
             $playerExists = $this->recursive_array_search($grossWinner->player_id, $winningPlayers);
82 79
             //if player is already there add money here to other money
83
-            if($playerExists){
80
+            if($playerExists) {
84 81
                 $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
85 82
                 $winningPlayers[$i]['money'] = ($grossWinner->money + $winningPlayers[$playerExists]['money']);
86 83
                 unset($winningPlayers[$playerExists]);
87
-            }
88
-            else{
84
+            } else {
89 85
                 $winningPlayers[$i]['player_id'] = $grossWinner->player_id;
90 86
                 $winningPlayers[$i]['money'] = $grossWinner->money;
91 87
             }
@@ -93,15 +89,14 @@  discard block
 block discarded – undo
93 89
         }
94 90
 
95 91
         $skinWinners = Skin::where('match_id', '=', $match->id)->get();
96
-        foreach($skinWinners as $key => $skinWinner){
92
+        foreach($skinWinners as $key => $skinWinner) {
97 93
             $playerExists = $this->recursive_array_search($skinWinner->player_id, $winningPlayers);
98 94
             //if player is already there add money here to other money
99
-            if($playerExists){
95
+            if($playerExists) {
100 96
                 $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
101 97
                 $winningPlayers[$i]['money'] = ($skinWinner->money + $winningPlayers[$playerExists]['money']);
102 98
                 unset($winningPlayers[$playerExists]);
103
-            }
104
-            else{
99
+            } else {
105 100
                 $winningPlayers[$i]['player_id'] = $skinWinner->player_id;
106 101
                 $winningPlayers[$i]['money'] = $skinWinner->money;
107 102
             }
@@ -109,11 +104,11 @@  discard block
 block discarded – undo
109 104
         }
110 105
 
111 106
         //Consolidate any multiple instances of a player
112
-        foreach ($winningPlayers as $key => $winningPlayer){
107
+        foreach ($winningPlayers as $key => $winningPlayer) {
113 108
             array_search($winningPlayer['player_id'], $winningPlayers);
114 109
         }
115 110
 
116
-        foreach ($winningPlayers as $key => $player){
111
+        foreach ($winningPlayers as $key => $player) {
117 112
             $currentPlayer = Player::find($player['player_id']);
118 113
             $attributes = array(
119 114
                 "winnings" => $player['money']
@@ -135,7 +130,8 @@  discard block
 block discarded – undo
135 130
         $events->listen('match.finalize', 'GolfLeague\Handlers\FinalizeHandler');
136 131
     }
137 132
 
138
-    public function recursive_array_search($needle,$haystack) {
133
+    public function recursive_array_search($needle,$haystack)
134
+    {
139 135
         foreach($haystack as $key=>$value) {
140 136
             $current_key=$key;
141 137
             if($needle===$value || (is_array($value) && $this->recursive_array_search($needle,$value) !== false)) {
Please login to merge, or discard this patch.