Passed
Branch master (7949ab)
by Tomáš
02:07
created
src/TournamentGenerator/Utilis/Sorter/Games.php 1 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 1 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/Preset/R2G.php 1 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/DoubleElimination.php 1 patch
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.
src/TournamentGenerator/Utilis/Sorter/Teams.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
 	* @return array Sorted array of teams
33 33
 	*/
34 34
 	public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) {
35
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
35
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
36
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
37
+		}
36 38
 
37 39
 		self::$ids = [$group->getId()];
38 40
 
@@ -58,7 +60,9 @@  discard block
 block discarded – undo
58 60
 	* @return array Sorted array of teams
59 61
 	*/
60 62
 	public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) {
61
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
63
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
64
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
65
+		}
62 66
 
63 67
 		self::$ids = $round->getGroupsIds();
64 68
 
@@ -79,8 +83,12 @@  discard block
 block discarded – undo
79 83
 	*/
80 84
 	private static function sortTeamsByPoints($a, $b) {
81 85
 		$groupsIds = self::$ids;
82
-		if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
83
-		if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
86
+		if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
87
+			return 0;
88
+		}
89
+		if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) {
90
+			return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
91
+		}
84 92
 		return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
85 93
 	}
86 94
 	/**
@@ -88,7 +96,9 @@  discard block
 block discarded – undo
88 96
 	*/
89 97
 	private static function sortTeamsByScore($a, $b) {
90 98
 		$groupsIds = self::$ids;
91
-		if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
99
+		if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
100
+			return 0;
101
+		}
92 102
 		return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
93 103
 	}
94 104
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Game.php 1 patch
Braces   +26 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,11 +33,15 @@  discard block
 block discarded – undo
33 33
 		$this->teams = $teams;
34 34
 		foreach ($this->teams as $team) {
35 35
 			foreach ($this->teams as $team2) {
36
-				if ($team === $team2) continue;
36
+				if ($team === $team2) {
37
+					continue;
38
+				}
37 39
 				$team->addGameWith($team2, $group);
38 40
 			}
39 41
 		}
40
-		if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true));
42
+		if (count($error) > 0) {
43
+			throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true));
44
+		}
41 45
 	}
42 46
 
43 47
 	public function getGroup() {
@@ -56,14 +60,18 @@  discard block
 block discarded – undo
56 60
 			$team->addGame($this);
57 61
 
58 62
 			foreach ($this->teams as $team2) {
59
-				if ($team === $team2) continue;
63
+				if ($team === $team2) {
64
+					continue;
65
+				}
60 66
 				if ($team instanceof Team) {
61 67
 					$team->addGameWith($team2, $this->group);
62 68
 					$team2->addGameWith($team, $this->group);
63 69
 				}
64 70
 			}
65 71
 		}
66
-		if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true));
72
+		if (count($error) > 0) {
73
+			throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true));
74
+		}
67 75
 		return $this;
68 76
 	}
69 77
 	public function getTeams(){
@@ -83,14 +91,20 @@  discard block
 block discarded – undo
83 91
 	* )
84 92
 	*/
85 93
 	public function setResults(array $results = []) {
86
-		if (count($this->results) === 0) $this->resetResults();
94
+		if (count($this->results) === 0) {
95
+			$this->resetResults();
96
+		}
87 97
 		arsort($results);
88 98
 		$inGame = /** @scrutinizer ignore-call */ $this->group->getInGame();
89 99
 		$i = 1;
90 100
 		foreach ($results as $id => $score) {
91
-			if (!is_numeric($score)) throw new \TypeError('Score passed to TournamentGenerator\Game::setResults() must be of the type numeric, '.gettype($score).' given');
101
+			if (!is_numeric($score)) {
102
+				throw new \TypeError('Score passed to TournamentGenerator\Game::setResults() must be of the type numeric, '.gettype($score).' given');
103
+			}
92 104
 			$team = $this->getTeam($id);
93
-			if (!$team instanceof Team) throw new \Exception('Couldn\'t find team with id of "'.$id.'"');
105
+			if (!$team instanceof Team) {
106
+				throw new \Exception('Couldn\'t find team with id of "'.$id.'"');
107
+			}
94 108
 			$this->results[$team->getId()] = ['score' => $score];
95 109
 			$team->addScore($score);
96 110
 			switch ($inGame) {
@@ -114,13 +128,11 @@  discard block
 block discarded – undo
114 128
 			$this->drawIds[] = $team->getId();
115 129
 			$team->addDraw($this->group->getId());
116 130
 			$this->results[$team->getId()] += ['points' => $this->group->drawPoints, 'type' => 'draw'];
117
-		}
118
-		elseif ($i === 1) {
131
+		} elseif ($i === 1) {
119 132
 			$this->winId = $team->getId();
120 133
 			$team->addWin($this->group->getId());
121 134
 			$this->results[$team->getId()] += ['points' => $this->group->winPoints, 'type' => 'win'];
122
-		}
123
-		else {
135
+		} else {
124 136
 			$this->lossId = $team->getId();
125 137
 			$team->addLoss($this->group->getId());
126 138
 			$this->results[$team->getId()] += ['points' => $this->group->lostPoints, 'type' => 'loss'];
@@ -220,7 +232,9 @@  discard block
 block discarded – undo
220 232
 	}
221 233
 
222 234
 	public function isPlayed() {
223
-		if (count($this->results) > 0) return true;
235
+		if (count($this->results) > 0) {
236
+			return true;
237
+		}
224 238
 		return false;
225 239
 	}
226 240
 }
Please login to merge, or discard this patch.
src/TournamentGenerator/Team.php 1 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/Utilis/FilterComparator.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 	private static function calcSum(\TournamentGenerator\Team $team, array $groupsId) {
53 53
 		$sum = 0;
54 54
 		foreach ($groupsId as $id) {
55
-			if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][self::$what];
55
+			if (isset($team->groupResults[$id])) {
56
+				$sum += $team->groupResults[$id][self::$what];
57
+			}
56 58
 		}
57 59
 		return $sum;
58 60
 	}
@@ -62,12 +64,16 @@  discard block
 block discarded – undo
62 64
 			$games = $team->getGames(null, reset($groupsId));
63 65
 			foreach ($games as $game) {
64 66
 				$results = $game->getResults()[$team->getId()];
65
-				if (($results[self::$what] > $max || $max === null)) $max = $results[self::$what];
67
+				if (($results[self::$what] > $max || $max === null)) {
68
+					$max = $results[self::$what];
69
+				}
66 70
 			}
67 71
 			return $max;
68 72
 		}
69 73
 		foreach ($groupsId as $id) {
70
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) $max = $team->groupResults[$id][self::$what];
74
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) {
75
+				$max = $team->groupResults[$id][self::$what];
76
+			}
71 77
 		}
72 78
 		return $max;
73 79
 	}
@@ -77,12 +83,16 @@  discard block
 block discarded – undo
77 83
 			$games = $team->getGames(null, reset($groupsId));
78 84
 			foreach ($games as $game) {
79 85
 				$results = $game->getResults()[$team->getId()];
80
-				if (($results[self::$what] < $min || $min === null)) $min = $results[self::$what];
86
+				if (($results[self::$what] < $min || $min === null)) {
87
+					$min = $results[self::$what];
88
+				}
81 89
 			}
82 90
 			return $min;
83 91
 		}
84 92
 		foreach ($groupsId as $id) {
85
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) $min = $team->groupResults[$id][self::$what];
93
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) {
94
+				$min = $team->groupResults[$id][self::$what];
95
+			}
86 96
 		}
87 97
 		return $min;
88 98
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/TeamFilter.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,11 +44,17 @@  discard block
 block discarded – undo
44 44
 	private $groups = [];
45 45
 
46 46
 	function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){
47
-		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')');
47
+		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) {
48
+			throw new \Exception('Trying to filter unexisting type ('.$what.')');
49
+		}
48 50
 		$this->what = strtolower($what);
49
-		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
51
+		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) {
52
+			throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
53
+		}
50 54
 		$this->how = $how;
51
-		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')');
55
+		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) {
56
+			throw new \Exception('Unsupported filter value type ('.gettype($val).')');
57
+		}
52 58
 		$this->val = $val;
53 59
 		$this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);}));
54 60
 	}
@@ -57,11 +63,17 @@  discard block
 block discarded – undo
57 63
 	}
58 64
 
59 65
 	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) {
60
-		if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
66
+		if (count($this->groups) > 0) {
67
+			$groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
68
+		}
61 69
 
62
-		if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
63
-		elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from);
64
-		elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from);
70
+		if ($this->what == 'team') {
71
+			return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
72
+		} elseif ($this->what == 'notprogressed') {
73
+			return !$this->validateProgressed($team, $from);
74
+		} elseif ($this->what == 'progressed') {
75
+			return $this->validateProgressed($team, $from);
76
+		}
65 77
 
66 78
 		return $this->validateCalc($team, $groupsId, $operation);
67 79
 	}
@@ -70,11 +82,15 @@  discard block
 block discarded – undo
70 82
 		return $this->val === $team;
71 83
 	}
72 84
 	private function validateProgressed(Team $team, Group $from = null) {
73
-		if ($from === null) throw new \Exception('Group $from was not defined.');
85
+		if ($from === null) {
86
+			throw new \Exception('Group $from was not defined.');
87
+		}
74 88
 		return $from->isProgressed($team);
75 89
 	}
76 90
 	private function validateCalc(Team $team, array $groupsId, string $operation = 'sum') {
77
-		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
91
+		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) {
92
+			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
93
+		}
78 94
 
79 95
 		return Utilis\FilterComparator::compare($operation, $this->val, $this->how, $this->what, $team, $groupsId);
80 96
 
Please login to merge, or discard this patch.