Completed
Push — master ( 8b93c6...635aa4 )
by Tomáš
02:08
created
src/TournamentGenerator/Utilis/Simulator.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
 			$game->setResults($results);
19 19
 		}
20 20
 		$return = $group->sortTeams($filters);
21
-		if (!$reset) return $return;
21
+		if (!$reset) {
22
+			return $return;
23
+		}
22 24
 		foreach ($group->getGames() as $game) {
23 25
 			$game->resetResults();
24 26
 		}
@@ -27,14 +29,18 @@  discard block
 block discarded – undo
27 29
 
28 30
 	public static function simulateRound(\TournamentGenerator\Round $round) {
29 31
 		foreach ($round->getGroups() as $group) {
30
-			if ($group->isPlayed()) continue;
32
+			if ($group->isPlayed()) {
33
+				continue;
34
+			}
31 35
 			$group->simulate([], false);
32 36
 		}
33 37
 		return true;
34 38
 	}
35 39
 
36 40
 	public static function simulateTournament(\TournamentGenerator\Tournament $tournament) {
37
-		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.');
41
+		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) {
42
+			throw new \Exception('There are no rounds or categories to simulate games from.');
43
+		}
38 44
 
39 45
 		$games = [];
40 46
 
@@ -55,7 +61,9 @@  discard block
 block discarded – undo
55 61
 
56 62
 	public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) {
57 63
 		$games = [];
58
-		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.');
64
+		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) {
65
+			throw new \Exception('There are no rounds or categories to simulate games from.');
66
+		}
59 67
 
60 68
 		foreach ($tournament->getCategories() as $category) {
61 69
 			$games = array_merge($games, $category->genGamesSimulate());
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Sorter/Games.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
 			// CYCLE 6
71 71
 			// FIRST AVAILABLE GAME
72
-			$this->moveCalculatedGames(array_shift($games),$teams);
72
+			$this->moveCalculatedGames(array_shift($games), $teams);
73 73
 		}
74 74
 
75 75
 		return $this->games;
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	private function cycle1(array &$games, array &$teams) {
80 80
 		$found = false;
81 81
 		foreach ($games as $key => $game) {
82
-			if ($this->orderCheckTeamsVal($game, $teams, [4,5,6,7])) {
83
-				$this->moveCalculatedGames($game,$teams);
82
+			if ($this->orderCheckTeamsVal($game, $teams, [4, 5, 6, 7])) {
83
+				$this->moveCalculatedGames($game, $teams);
84 84
 				unset($games[$key]);
85 85
 				$found = true;
86 86
 				break;
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	private function cycle2(array &$games, array &$teams) {
93 93
 		$found = false;
94 94
 		foreach ($games as $key => $game) {
95
-			if ($this->orderCheckTeamsVal($game, $teams, [6,7])) {
96
-				$this->moveCalculatedGames($game,$teams);
95
+			if ($this->orderCheckTeamsVal($game, $teams, [6, 7])) {
96
+				$this->moveCalculatedGames($game, $teams);
97 97
 				unset($games[$key]);
98 98
 				$found = true;
99 99
 				break;
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	private function cycle3(array &$games, array &$teams) {
107 107
 		$found = false;
108 108
 		foreach ($games as $key => $game) {
109
-			if ($this->orderCheckTeamsVal($game, $teams, [7], [1,2,3])) {
110
-				$this->moveCalculatedGames($game,$teams);
109
+			if ($this->orderCheckTeamsVal($game, $teams, [7], [1, 2, 3])) {
110
+				$this->moveCalculatedGames($game, $teams);
111 111
 				unset($games[$key]);
112 112
 				$found = true;
113 113
 				break;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		$found = false;
121 121
 		foreach ($games as $key => $game) {
122 122
 			if ($this->orderCheckTeamsVal($game, $teams, [7])) {
123
-				$this->moveCalculatedGames($game,$teams);
123
+				$this->moveCalculatedGames($game, $teams);
124 124
 				unset($games[$key]);
125 125
 				$found = true;
126 126
 				break;
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	private function cycle5(array &$games, array &$teams) {
133 133
 		$found = false;
134 134
 		foreach ($games as $key => $game) {
135
-			if ($this->orderCheckTeamsVal($game, $teams, [], [1,2,3])) {
136
-				$this->moveCalculatedGames($game,$teams);
135
+			if ($this->orderCheckTeamsVal($game, $teams, [], [1, 2, 3])) {
136
+				$this->moveCalculatedGames($game, $teams);
137 137
 				unset($games[$key]);
138 138
 				$found = true;
139 139
 				break;
Please login to merge, or discard this patch.
Braces   +27 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 
37 37
 		$games = $this->group->getGames();
38 38
 
39
-		if (count($games) <= 4) return $games;
39
+		if (count($games) <= 4) {
40
+			return $games;
41
+		}
40 42
 
41 43
 		$this->games = [];
42 44
 
@@ -48,24 +50,34 @@  discard block
 block discarded – undo
48 50
 		while (count($games) > 0) {
49 51
 			// CYCLE 1
50 52
 			// TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4)
51
-			if ($this->cycle1($games, $teams)) continue;
53
+			if ($this->cycle1($games, $teams)) {
54
+				continue;
55
+			}
52 56
 
53 57
 			// CYCLE 2
54 58
 			// NOT TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7)
55
-			if ($this->cycle2($games, $teams)) continue;
59
+			if ($this->cycle2($games, $teams)) {
60
+				continue;
61
+			}
56 62
 
57 63
 			// CYCLE 3
58 64
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
59 65
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
60
-			if ($this->cycle3($games, $teams)) continue;
66
+			if ($this->cycle3($games, $teams)) {
67
+				continue;
68
+			}
61 69
 
62 70
 			// CYCLE 4
63 71
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
64
-			if ($this->cycle4($games, $teams)) continue;
72
+			if ($this->cycle4($games, $teams)) {
73
+				continue;
74
+			}
65 75
 
66 76
 			// CYCLE 5
67 77
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
68
-			if ($this->cycle5($games, $teams)) continue;
78
+			if ($this->cycle5($games, $teams)) {
79
+				continue;
80
+			}
69 81
 
70 82
 			// CYCLE 6
71 83
 			// FIRST AVAILABLE GAME
@@ -174,11 +186,17 @@  discard block
 block discarded – undo
174 186
 		$requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); });
175 187
 
176 188
 		foreach ($game->getTeamsIds() as $tid) {
177
-			if (in_array($teams[$tid], $checkVals)) return false;
178
-			if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]);
189
+			if (in_array($teams[$tid], $checkVals)) {
190
+				return false;
191
+			}
192
+			if (isset($requiredTeams[$tid])) {
193
+				unset($requiredTeams[$tid]);
194
+			}
179 195
 		}
180 196
 
181
-		if (count($requiredTeams) > 0) return false;
197
+		if (count($requiredTeams) > 0) {
198
+			return false;
199
+		}
182 200
 
183 201
 		return true;
184 202
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Generator.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 		$this->group = $group;
19 19
 	}
20 20
 
21
-	public function allowSkip(){
21
+	public function allowSkip() {
22 22
 		$this->allowSkip = true;
23 23
 		return $this;
24 24
 	}
25
-	public function disallowSkip(){
25
+	public function disallowSkip() {
26 26
 		$this->allowSkip = false;
27 27
 		return $this;
28 28
 	}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 	public function setInGame(int $inGame) {
48
-		if ($inGame < 2 ||  $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
48
+		if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
49 49
 		$this->inGame = $inGame;
50 50
 		return $this;
51 51
 	}
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
 		$discard = [];
121 121
 		shuffle($teams);
122 122
 		$count = count($teams);
123
-		while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); }
123
+		while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); }
124 124
 
125 125
 		while (count($teams) > 0) {
126 126
 			$tInGame = [];
127
-			for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); }
127
+			for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); }
128 128
 			$this->group->game($tInGame);
129 129
 		}
130 130
 
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
 	public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) {
166 166
 		$bracket = []; // ARRAY OF GAMES
167 167
 
168
-		if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
168
+		if (count($teams)%2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
169 169
 
170 170
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
171 171
 
172
-		for ($i=0; $i < count($teams)-1; $i++) {
172
+		for ($i = 0; $i < count($teams)-1; $i++) {
173 173
 			$bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND
174 174
 
175 175
 			$teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
 		$bracket = [];
185 185
 
186
-		for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
186
+		for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
187 187
 
188 188
 			$home = $teams[$i];
189 189
 			$reverse = array_reverse($teams);
Please login to merge, or discard this patch.
Braces   +37 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,8 +36,11 @@  discard block
 block discarded – undo
36 36
 
37 37
 
38 38
 	public function setType(/** @scrutinizer ignore-all */ string $type = \TournamentGenerator\Constants::ROUND_ROBIN) {
39
-		if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) $this->type = $type;
40
-		else throw new \Exception('Unknown group type: '.$type);
39
+		if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) {
40
+			$this->type = $type;
41
+		} else {
42
+			throw new \Exception('Unknown group type: '.$type);
43
+		}
41 44
 		return $this;
42 45
 	}
43 46
 	public function getType() {
@@ -45,7 +48,9 @@  discard block
 block discarded – undo
45 48
 	}
46 49
 
47 50
 	public function setInGame(int $inGame) {
48
-		if ($inGame < 2 ||  $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
51
+		if ($inGame < 2 ||  $inGame > 4) {
52
+			throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
53
+		}
49 54
 		$this->inGame = $inGame;
50 55
 		return $this;
51 56
 	}
@@ -54,7 +59,9 @@  discard block
 block discarded – undo
54 59
 	}
55 60
 
56 61
 	public function setMaxSize(int $maxSize) {
57
-		if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
62
+		if ($maxSize < 2) {
63
+			throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
64
+		}
58 65
 		$this->maxSize = $maxSize;
59 66
 		return $this;
60 67
 	}
@@ -78,7 +85,9 @@  discard block
 block discarded – undo
78 85
 	}
79 86
 	private function r_rGames(array $teams = []) {
80 87
 		$games = [];
81
-		if (count($teams) === 0) $teams = $this->group->getTeams();
88
+		if (count($teams) === 0) {
89
+			$teams = $this->group->getTeams();
90
+		}
82 91
 		switch ($this->inGame) {
83 92
 			case 2:
84 93
 				$games = Generator::circle_genGames2($teams, $this->group);
@@ -98,7 +107,9 @@  discard block
 block discarded – undo
98 107
 			$lockedTeam = array_shift($teamsB);
99 108
 			$gamesTemp = Generator::circle_genGames2($teamsB, $this->group);
100 109
 			foreach ($gamesTemp as $game) {
101
-				if (isset($lockedTeam1)) $game->addTeam($lockedTeam1);
110
+				if (isset($lockedTeam1)) {
111
+					$game->addTeam($lockedTeam1);
112
+				}
102 113
 				$game->addTeam($lockedTeam);
103 114
 			}
104 115
 			$games = array_merge($games, $gamesTemp);
@@ -116,7 +127,9 @@  discard block
 block discarded – undo
116 127
 		return $games;
117 128
 	}
118 129
 	private function two_twoGames(array $teams = []) {
119
-		if (count($teams) === 0) $teams = $this->group->getTeams();
130
+		if (count($teams) === 0) {
131
+			$teams = $this->group->getTeams();
132
+		}
120 133
 		$discard = [];
121 134
 		shuffle($teams);
122 135
 		$count = count($teams);
@@ -128,13 +141,17 @@  discard block
 block discarded – undo
128 141
 			$this->group->game($tInGame);
129 142
 		}
130 143
 
131
-		if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False'));
144
+		if (count($discard) > 0 && !$this->allowSkip) {
145
+			throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False'));
146
+		}
132 147
 
133 148
 		return $this;
134 149
 	}
135 150
 	private function cond_splitGames(array $teams = []) {
136 151
 		$games = [];
137
-		if (count($teams) === 0) $teams = $this->group->getTeams();
152
+		if (count($teams) === 0) {
153
+			$teams = $this->group->getTeams();
154
+		}
138 155
 
139 156
 		if (count($teams) > $this->maxSize) {
140 157
 			$groups = array_chunk($teams, /** @scrutinizer ignore-type */ ceil(count($teams)/ceil(count($teams)/$this->maxSize))); // SPLIT TEAMS INTO GROUP OF MAXIMUM SIZE OF $this->maxSize
@@ -144,7 +161,9 @@  discard block
 block discarded – undo
144 161
 			while ($g > 0) {
145 162
 				foreach ($games as $key => $group) {
146 163
 					$this->group->addGame(array_shift($games[$key]));
147
-					if (count($games[$key]) === 0) unset($games[$key]);
164
+					if (count($games[$key]) === 0) {
165
+						unset($games[$key]);
166
+					}
148 167
 					$g--;
149 168
 				}
150 169
 			}
@@ -165,7 +184,10 @@  discard block
 block discarded – undo
165 184
 	public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) {
166 185
 		$bracket = []; // ARRAY OF GAMES
167 186
 
168
-		if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
187
+		if (count($teams) % 2 != 0) {
188
+			$teams[] = \TournamentGenerator\Constants::DUMMY_TEAM;
189
+		}
190
+		// IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
169 191
 
170 192
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
171 193
 
@@ -189,7 +211,10 @@  discard block
 block discarded – undo
189 211
 			$reverse = array_reverse($teams);
190 212
 			$away = $reverse[$i];
191 213
 
192
-			if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT
214
+			if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) {
215
+				continue;
216
+			}
217
+			// SKIP WHEN DUMMY_TEAM IS PRESENT
193 218
 
194 219
 			$bracket[] = new \TournamentGenerator\Game([$home, $away], $group);
195 220
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Team.php 3 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@
 block discarded – undo
16 16
 	public $sumScore = 0;
17 17
 
18 18
 	/**
19
-	* ARRAY WITH GROUPS AND IT'S RESULTS
20
-	* array (
21
-	* * groupId => array (
22
-	* * * "group"  => Group, # GROUP OBJECT
23
-	* * * "points" => int 0, # NUMBER OF POINTS AQUIRED
24
-	* * * "score"  => int 0, # SUM OF SCORE AQUIRED
25
-	* * * "wins"   => int 0, # NUMBER OF WINS
26
-	* * * "draws"  => int 0, # NUMBER OF DRAWS
27
-	* * * "losses" => int 0, # NUMBER OF LOSSES
28
-	* * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4)
29
-	* * * "third"  => int 0  # NUMBER OF TIMES BEING THIRD  (ONLY FOR INGAME OPTION OF 4)
30
-	* * )
31
-	*)
32
-	*/
19
+	 * ARRAY WITH GROUPS AND IT'S RESULTS
20
+	 * array (
21
+	 * * groupId => array (
22
+	 * * * "group"  => Group, # GROUP OBJECT
23
+	 * * * "points" => int 0, # NUMBER OF POINTS AQUIRED
24
+	 * * * "score"  => int 0, # SUM OF SCORE AQUIRED
25
+	 * * * "wins"   => int 0, # NUMBER OF WINS
26
+	 * * * "draws"  => int 0, # NUMBER OF DRAWS
27
+	 * * * "losses" => int 0, # NUMBER OF LOSSES
28
+	 * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4)
29
+	 * * * "third"  => int 0  # NUMBER OF TIMES BEING THIRD  (ONLY FOR INGAME OPTION OF 4)
30
+	 * * )
31
+	 *)
32
+	 */
33 33
 	public $groupResults = [];
34 34
 
35 35
 	function __construct(string $name = 'team', $id = null) {
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -121,14 +121,14 @@  discard block
 block discarded – undo
121 121
 		return $this->sumScore;
122 122
 	}
123 123
 
124
-	public function addWin(string $groupId = ''){
124
+	public function addWin(string $groupId = '') {
125 125
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
126 126
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
127 127
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
128 128
 		$this->groupResults[$groupId]['wins']++;
129 129
 		return $this;
130 130
 	}
131
-	public function removeWin(string $groupId = ''){
131
+	public function removeWin(string $groupId = '') {
132 132
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
133 133
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
134 134
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 		return $this;
137 137
 	}
138 138
 
139
-	public function addDraw(string $groupId = ''){
139
+	public function addDraw(string $groupId = '') {
140 140
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
141 141
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
142 142
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
143 143
 		$this->groupResults[$groupId]['draws']++;
144 144
 		return $this;
145 145
 	}
146
-	public function removeDraw(string $groupId = ''){
146
+	public function removeDraw(string $groupId = '') {
147 147
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
148 148
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPoints;
149 149
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 		return $this;
152 152
 	}
153 153
 
154
-	public function addLoss(string $groupId = ''){
154
+	public function addLoss(string $groupId = '') {
155 155
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
156 156
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
157 157
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
158 158
 		$this->groupResults[$groupId]['losses']++;
159 159
 		return $this;
160 160
 	}
161
-	public function removeLoss(string $groupId = ''){
161
+	public function removeLoss(string $groupId = '') {
162 162
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
163 163
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
164 164
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
 		return $this;
167 167
 	}
168 168
 
169
-	public function addSecond(string $groupId = ''){
169
+	public function addSecond(string $groupId = '') {
170 170
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
171 171
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
172 172
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
173 173
 		$this->groupResults[$groupId]['second']++;
174 174
 		return $this;
175 175
 	}
176
-	public function removeSecond(string $groupId = ''){
176
+	public function removeSecond(string $groupId = '') {
177 177
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
178 178
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
179 179
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
 		return $this;
182 182
 	}
183 183
 
184
-	public function addThird(string $groupId = ''){
184
+	public function addThird(string $groupId = '') {
185 185
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
186 186
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
187 187
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
188 188
 		$this->groupResults[$groupId]['third']++;
189 189
 		return $this;
190 190
 	}
191
-	public function removeThird(string $groupId = ''){
191
+	public function removeThird(string $groupId = '') {
192 192
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
193 193
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
194 194
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
Please login to merge, or discard this patch.
Braces   +60 added lines, -20 removed lines patch added patch discarded remove patch
@@ -75,20 +75,26 @@  discard block
 block discarded – undo
75 75
 	}
76 76
 	public function getGroupResults($groupId = null) {
77 77
 		if (isset($groupId)) {
78
-			if (!isset($this->groupResults[$groupId])) throw new \Exception('Trying to get unexisting group results ('.$groupId.')');
78
+			if (!isset($this->groupResults[$groupId])) {
79
+				throw new \Exception('Trying to get unexisting group results ('.$groupId.')');
80
+			}
79 81
 			return $this->groupResults[$groupId];
80 82
 		}
81 83
 		return $this->groupResults;
82 84
 	}
83 85
 
84 86
 	public function addGameWith(Team $team, Group $group) {
85
-		if (!isset($this->gamesWith[$group->getId()][$team->getId()])) $this->gamesWith[$group->getId()][$team->getId()] = 0;
87
+		if (!isset($this->gamesWith[$group->getId()][$team->getId()])) {
88
+			$this->gamesWith[$group->getId()][$team->getId()] = 0;
89
+		}
86 90
 		$this->gamesWith[$group->getId()][$team->getId()]++;
87 91
 		return $this;
88 92
 	}
89 93
 	public function getGameWith(Team $team = null, Group $group = null) {
90 94
 		if (isset($group)) {
91
-			if (isset($team)) return $this->gamesWith[$group->getId()][$team->getId()];
95
+			if (isset($team)) {
96
+				return $this->gamesWith[$group->getId()][$team->getId()];
97
+			}
92 98
 			return $this->gamesWith[$group->getId()];
93 99
 		}
94 100
 		if (isset($team)) {
@@ -97,25 +103,35 @@  discard block
 block discarded – undo
97 103
 				$filter = array_filter($games, function($key) use ($team){
98 104
 					return $key === $team->getId();
99 105
 				}, ARRAY_FILTER_USE_KEY);
100
-				if (count($filter) > 0) $return[$id] = $filter;
106
+				if (count($filter) > 0) {
107
+					$return[$id] = $filter;
108
+				}
101 109
 			}
102 110
 			return $return;
103 111
 		}
104 112
 		return $this->gamesWith;
105 113
 	}
106 114
 	public function addGroup(Group $group) {
107
-		if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = [];
115
+		if (!isset($this->games[$group->getId()])) {
116
+			$this->games[$group->getId()] = [];
117
+		}
108 118
 		return $this;
109 119
 	}
110 120
 	public function addGame(Game $game) {
111 121
 		$group = $game->getGroup();
112
-		if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = [];
122
+		if (!isset($this->games[$group->getId()])) {
123
+			$this->games[$group->getId()] = [];
124
+		}
113 125
 		$this->games[$group->getId()][] = $game;
114 126
 		return $this;
115 127
 	}
116 128
 	public function getGames(Group $group = null, $groupId = null) {
117
-		if (isset($group) && isset($this->games[$group->getId()])) return $this->games[$group->getId()];
118
-		if (isset($groupId) && isset($this->games[$groupId])) return $this->games[$groupId];
129
+		if (isset($group) && isset($this->games[$group->getId()])) {
130
+			return $this->games[$group->getId()];
131
+		}
132
+		if (isset($groupId) && isset($this->games[$groupId])) {
133
+			return $this->games[$groupId];
134
+		}
119 135
 		return $this->games;
120 136
 	}
121 137
 
@@ -127,14 +143,18 @@  discard block
 block discarded – undo
127 143
 	}
128 144
 
129 145
 	public function addWin(string $groupId = ''){
130
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
146
+		if (!isset($this->groupResults[$groupId])) {
147
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
148
+		}
131 149
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
132 150
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
133 151
 		$this->groupResults[$groupId]['wins']++;
134 152
 		return $this;
135 153
 	}
136 154
 	public function removeWin(string $groupId = ''){
137
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
155
+		if (!isset($this->groupResults[$groupId])) {
156
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
157
+		}
138 158
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
139 159
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
140 160
 		$this->groupResults[$groupId]['wins']--;
@@ -142,14 +162,18 @@  discard block
 block discarded – undo
142 162
 	}
143 163
 
144 164
 	public function addDraw(string $groupId = ''){
145
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
165
+		if (!isset($this->groupResults[$groupId])) {
166
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
167
+		}
146 168
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
147 169
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
148 170
 		$this->groupResults[$groupId]['draws']++;
149 171
 		return $this;
150 172
 	}
151 173
 	public function removeDraw(string $groupId = ''){
152
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
174
+		if (!isset($this->groupResults[$groupId])) {
175
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
176
+		}
153 177
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPoints;
154 178
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
155 179
 		$this->groupResults[$groupId]['draws']--;
@@ -157,14 +181,18 @@  discard block
 block discarded – undo
157 181
 	}
158 182
 
159 183
 	public function addLoss(string $groupId = ''){
160
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
184
+		if (!isset($this->groupResults[$groupId])) {
185
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
186
+		}
161 187
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
162 188
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
163 189
 		$this->groupResults[$groupId]['losses']++;
164 190
 		return $this;
165 191
 	}
166 192
 	public function removeLoss(string $groupId = ''){
167
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
193
+		if (!isset($this->groupResults[$groupId])) {
194
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
195
+		}
168 196
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
169 197
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
170 198
 		$this->groupResults[$groupId]['losses']--;
@@ -172,14 +200,18 @@  discard block
 block discarded – undo
172 200
 	}
173 201
 
174 202
 	public function addSecond(string $groupId = ''){
175
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
203
+		if (!isset($this->groupResults[$groupId])) {
204
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
205
+		}
176 206
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
177 207
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
178 208
 		$this->groupResults[$groupId]['second']++;
179 209
 		return $this;
180 210
 	}
181 211
 	public function removeSecond(string $groupId = ''){
182
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
212
+		if (!isset($this->groupResults[$groupId])) {
213
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
214
+		}
183 215
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
184 216
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
185 217
 		$this->groupResults[$groupId]['second']--;
@@ -187,14 +219,18 @@  discard block
 block discarded – undo
187 219
 	}
188 220
 
189 221
 	public function addThird(string $groupId = ''){
190
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
222
+		if (!isset($this->groupResults[$groupId])) {
223
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
224
+		}
191 225
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
192 226
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
193 227
 		$this->groupResults[$groupId]['third']++;
194 228
 		return $this;
195 229
 	}
196 230
 	public function removeThird(string $groupId = ''){
197
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
231
+		if (!isset($this->groupResults[$groupId])) {
232
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
233
+		}
198 234
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
199 235
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
200 236
 		$this->groupResults[$groupId]['third']--;
@@ -202,7 +238,9 @@  discard block
 block discarded – undo
202 238
 	}
203 239
 
204 240
 	public function sumPoints(array $groupIds = []) {
205
-		if (count($groupIds) === 0) return $this->sumPoints;
241
+		if (count($groupIds) === 0) {
242
+			return $this->sumPoints;
243
+		}
206 244
 		$sum = 0;
207 245
 		foreach ($groupIds as $gid) {
208 246
 			$sum += $this->groupResults[$gid]['points'] ?? 0;
@@ -210,7 +248,9 @@  discard block
 block discarded – undo
210 248
 		return $sum;
211 249
 	}
212 250
 	public function sumScore(array $groupIds = []) {
213
-		if (count($groupIds) === 0) return $this->sumScore;
251
+		if (count($groupIds) === 0) {
252
+			return $this->sumScore;
253
+		}
214 254
 		$sum = 0;
215 255
 		foreach ($groupIds as $gid) {
216 256
 			$sum += $this->groupResults[$gid]['score'] ?? 0;
Please login to merge, or discard this patch.
src/TournamentGenerator/Progression.php 1 patch
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,11 +33,17 @@  discard block
 block discarded – undo
33 33
 	}
34 34
 
35 35
 	public function progress(bool $blank = false) {
36
-		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters);
37
-		else $teams = $this->from->sortTeams($this->filters);
36
+		if ($blank) {
37
+			$teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters);
38
+		} else {
39
+			$teams = $this->from->sortTeams($this->filters);
40
+		}
38 41
 
39
-		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
40
-		else $next = $teams;
42
+		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) {
43
+			$next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
44
+		} else {
45
+			$next = $teams;
46
+		}
41 47
 
42 48
 		$i = 1;
43 49
 
@@ -45,12 +51,15 @@  discard block
 block discarded – undo
45 51
 			if ($blank) {
46 52
 				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team));
47 53
 				$i++;
54
+			} else {
55
+				$team->sumPoints += $this->from->progressPoints;
48 56
 			}
49
-			else $team->sumPoints += $this->from->progressPoints;
50 57
 		}
51 58
 
52 59
 		$this->from->addProgressed($next);
53
-		if (!$blank) $this->to->addTeam($next);
60
+		if (!$blank) {
61
+			$this->to->addTeam($next);
62
+		}
54 63
 		return $this;
55 64
 	}
56 65
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Category.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		$this->name = $name;
20 20
 	}
21 21
 
22
-	public function addRound(Round ...$rounds){
22
+	public function addRound(Round ...$rounds) {
23 23
 		foreach ($rounds as $round) {
24 24
 			if ($round instanceof Round) $this->rounds[] = $round;
25 25
 			else throw new \Exception('Trying to add round which is not an instance of Round class.');
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
 		$this->rounds[] = $r->setSkip($this->allowSkip);
32 32
 		return $r;
33 33
 	}
34
-	public function getRounds(){
34
+	public function getRounds() {
35 35
 		return $this->rounds;
36 36
 	}
37 37
 
38
-	public function allowSkip(){
38
+	public function allowSkip() {
39 39
 		$this->allowSkip = true;
40 40
 		return $this;
41 41
 	}
42
-	public function disallowSkip(){
42
+	public function disallowSkip() {
43 43
 		$this->allowSkip = false;
44 44
 		return $this;
45 45
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,8 +21,11 @@  discard block
 block discarded – undo
21 21
 
22 22
 	public function addRound(Round ...$rounds){
23 23
 		foreach ($rounds as $round) {
24
-			if ($round instanceof Round) $this->rounds[] = $round;
25
-			else throw new \Exception('Trying to add round which is not an instance of Round class.');
24
+			if ($round instanceof Round) {
25
+				$this->rounds[] = $round;
26
+			} else {
27
+				throw new \Exception('Trying to add round which is not an instance of Round class.');
28
+			}
26 29
 		}
27 30
 		return $this;
28 31
 	}
@@ -63,7 +66,9 @@  discard block
 block discarded – undo
63 66
 		return $t;
64 67
 	}
65 68
 	public function getTeams() {
66
-		if (count($this->teams) > 0) return $this->teams;
69
+		if (count($this->teams) > 0) {
70
+			return $this->teams;
71
+		}
67 72
 		$teams = [];
68 73
 		foreach ($this->rounds as $round) {
69 74
 			$teams = array_merge($teams, $round->getTeams());
@@ -82,7 +87,9 @@  discard block
 block discarded – undo
82 87
 
83 88
 	public function splitTeams(...$rounds) {
84 89
 
85
-		if (count($rounds) === 0) $rounds = $this->getRounds();
90
+		if (count($rounds) === 0) {
91
+			$rounds = $this->getRounds();
92
+		}
86 93
 
87 94
 		$teams = $this->getTeams();
88 95
 		shuffle($teams);
@@ -102,7 +109,9 @@  discard block
 block discarded – undo
102 109
 
103 110
 	public function genGamesSimulate() {
104 111
 		$games = [];
105
-		if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.');
112
+		if (count($this->rounds) <= 0) {
113
+			throw new \Exception('There are no rounds to simulate games from.');
114
+		}
106 115
 		foreach ($this->rounds as $round) {
107 116
 			$games = array_merge($games, $round->genGames());
108 117
 			$round->simulate()->progress(true)->resetGames();
Please login to merge, or discard this patch.
src/TournamentGenerator/Preset/R2G.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
 		$this->splitTeams($round1);
32 32
 
33
-		if (count($this->getTeams()) % 4 == 2) {
33
+		if (count($this->getTeams())%4 == 2) {
34 34
 			$group_top = $round2->group('TOP')->setType(\TournamentGenerator\Constants::ROUND_TWO);
35 35
 
36 36
 			$filter_win_2 = new \TournamentGenerator\TeamFilter('wins', '=', 2, [$group_0_0, $group_top]);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@
 block discarded – undo
12 12
 
13 13
 	public function generate() {
14 14
 
15
-		if (count($this->getTeams()) === 0) throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.');
15
+		if (count($this->getTeams()) === 0) {
16
+			throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.');
17
+		}
16 18
 
17 19
 
18 20
 		$round1 = $this->round('Round 1');
Please login to merge, or discard this patch.
src/TournamentGenerator/Preset/SingleElimination.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 		// CALCULATE BYES
18 18
 		$byes = 0;
19
-		if ( !\TournamentGenerator\isPowerOf2($countTeams) ) {
19
+		if (!\TournamentGenerator\isPowerOf2($countTeams)) {
20 20
 			$nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT));
21 21
 			$byes = $nextPow-$countTeams;
22 22
 		}
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
 
28 28
 		$previousGroups = [];
29 29
 
30
-		for ($i=1; $i <= (($countTeams+$byes)/2); $i++) {
30
+		for ($i = 1; $i <= (($countTeams+$byes)/2); $i++) {
31 31
 			$g = $startRound->group('Round 1 '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO);
32 32
 			$previousGroups[] = $g;
33 33
 		}
34 34
 
35 35
 		$this->splitTeams();
36 36
 
37
-		for ($r=2; $r <= $roundsNum; $r++) {
37
+		for ($r = 2; $r <= $roundsNum; $r++) {
38 38
 			$groups = [];
39 39
 			$round = $this->round('Round '.$r);
40
-			for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
40
+			for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
41 41
 				$group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO);
42 42
 				$groups[] = $group;
43 43
 				array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE
Please login to merge, or discard this patch.
src/TournamentGenerator/Preset/DoubleElimination.php 2 patches
Braces   +18 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 		$countTeams = count($this->getTeams());
15 15
 
16
-		if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.');
16
+		if ($countTeams < 3) {
17
+			throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.');
18
+		}
17 19
 
18 20
 
19 21
 		// CALCULATE BYES
@@ -131,15 +133,19 @@  discard block
 block discarded – undo
131 133
 				if ($r === 2) { // FIRST LOSING ROUND
132 134
 					$previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP
133 135
 					$previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP
134
-				}
135
-				elseif ($losingGroupTeamsCount >= 2) {
136
+				} elseif ($losingGroupTeamsCount >= 2) {
136 137
 					$previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
137
-					if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE
138
-					else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE
138
+					if (isset(array_reverse($previousGroups)[$g-1])) {
139
+						array_reverse($previousGroups)[$g-1]->progression($group, 1, 1);
140
+					}
141
+					// PROGREESS FROM WINNING GROUP BEFORE
142
+					else {
143
+						$previousLosingGroups[$g]->progression($group, 0, 1);
144
+					}
145
+					// PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE
139 146
 				}
140 147
 			}
141
-		}
142
-		else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES
148
+		} else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES
143 149
 			// LOOK FOR THE CLOSEST LOWER POWER OF 2
144 150
 			$losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT));
145 151
 			$n = (floor(count($previousLosingGroups)/2)+$losingByes);
@@ -163,10 +169,12 @@  discard block
 block discarded – undo
163 169
 				if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE
164 170
 					$previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE
165 171
 					$byesProgressed++;
166
-				}
167
-				else {
172
+				} else {
168 173
 					$previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
169
-					if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
174
+					if (isset($previousLosingGroups[$lastGroup + 1])) {
175
+						$previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1);
176
+					}
177
+					// PROGREESS FROM LOSING GROUP BEFORE
170 178
 					$lastGroup += 2;
171 179
 				}
172 180
 			}
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 		$groupIds = [];
32 32
 		$allGroups = [];
33 33
 
34
-		for ($i=1; $i <= $startGroups; $i++) {
34
+		for ($i = 1; $i <= $startGroups; $i++) {
35 35
 			$g = $startRound->group('Start group - '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO);
36 36
 			$allGroups[] = $g;
37 37
 			$groupIds[] = $g->getId();
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		// SPLIT TEAMS EVENLY
42 42
 		$this->splitTeams();
43 43
 
44
-		for ($r=2; $r <= $roundsNum-1; $r++) {
44
+		for ($r = 2; $r <= $roundsNum-1; $r++) {
45 45
 			$groups = [];
46 46
 			$losingGroups = [];
47 47
 			$round = $this->round('Round '.$r);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	private function calcByes(int $countTeams, int &$nextPow) {
76 76
 		$byes = 0;
77 77
 		$nextPow = $countTeams;
78
-		if ( !\TournamentGenerator\isPowerOf2($countTeams) ) {
78
+		if (!\TournamentGenerator\isPowerOf2($countTeams)) {
79 79
 			$nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT));
80 80
 			$byes = $nextPow-$countTeams;
81 81
 		}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 	private function generateWinSide(int &$r, int &$byes, int &$countTeams, \TournamentGenerator\Round &$round, array &$allGroups, array &$groups, \TournamentGenerator\Group &$lastWinningGroup = null, array &$previousGroups = []) {
85 85
 		$order = 1;
86
-		for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
86
+		for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
87 87
 			$group = $round->group('Round '.$r.' - win '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order);
88 88
 			$allGroups[] = $group;
89 89
 			$order += 2;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		$losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups);
99 99
 		$order = 2;
100 100
 		if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES
101
-			for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) {
101
+			for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) {
102 102
 				$group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order);
103 103
 				$allGroups[] = $group;
104 104
 				$order += 2;
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 			$n = (floor(count($previousLosingGroups)/2)+$losingByes);
122 122
 			$byesGroupsNums = [];
123 123
 			$byesProgressed = 0;
124
-			for ($i=0; $i < $losingByes; $i++) {
124
+			for ($i = 0; $i < $losingByes; $i++) {
125 125
 				$byesGroupsNums[] = $n-($i*2);
126 126
 			}
127 127
 			$lastGroup = 0;
128
-			for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) {
128
+			for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) {
129 129
 				$group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order);
130 130
 				$allGroups[] = $group;
131 131
 				$order += 2;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 				}
138 138
 				else {
139 139
 					$previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
140
-					if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
140
+					if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
141 141
 					$lastGroup += 2;
142 142
 				}
143 143
 			}
Please login to merge, or discard this patch.