Completed
Push — master ( 5d9f44...4b85e8 )
by Tomáš
03:31
created
src/TournamentGenerator/TeamFilter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@
 block discarded – undo
43 43
 
44 44
 	private $groups = [];
45 45
 
46
-	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){
46
+	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) {
47 47
 		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what);
48 48
 		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how;
49 49
 		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val;
50
-		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group);}));
50
+		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group); }));
51 51
 	}
52 52
 	public function __toString() {
53 53
 		return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : '');
Please login to merge, or discard this patch.
Braces   +37 added lines, -13 removed lines patch added patch discarded remove patch
@@ -44,9 +44,15 @@  discard block
 block discarded – undo
44 44
 	private $groups = [];
45 45
 
46 46
 	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){
47
-		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what);
48
-		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how;
49
-		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val;
47
+		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) {
48
+			$this->what = strtolower($what);
49
+		}
50
+		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) {
51
+			$this->how = $how;
52
+		}
53
+		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) {
54
+			$this->val = $val;
55
+		}
50 56
 		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group);}));
51 57
 	}
52 58
 	public function __toString() {
@@ -54,11 +60,17 @@  discard block
 block discarded – undo
54 60
 	}
55 61
 
56 62
 	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) {
57
-		if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
63
+		if (count($this->groups) > 0) {
64
+			$groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
65
+		}
58 66
 
59
-		if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
60
-		elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from);
61
-		elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from);
67
+		if ($this->what == 'team') {
68
+			return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
69
+		} elseif ($this->what == 'notprogressed') {
70
+			return !$this->validateProgressed($team, $from);
71
+		} elseif ($this->what == 'progressed') {
72
+			return $this->validateProgressed($team, $from);
73
+		}
62 74
 
63 75
 		return $this->validateCalc($team, $groupsId, $operation);
64 76
 	}
@@ -67,13 +79,19 @@  discard block
 block discarded – undo
67 79
 		return $this->val === $team;
68 80
 	}
69 81
 	private function validateProgressed(Team $team, Group $from = null) {
70
-		if ($from === null) throw new \Exception('Group $from was not defined.');
82
+		if ($from === null) {
83
+			throw new \Exception('Group $from was not defined.');
84
+		}
71 85
 		return $from->isProgressed($team);
72 86
 	}
73 87
 	private function validateCalc(Team $team, $groupsId, string $operation = 'sum') {
74
-		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.');
88
+		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) {
89
+			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
90
+		}
75 91
 		$comp = 0;
76
-		if (gettype($groupsId) === 'string') $groupsId = [$groupsId];
92
+		if (gettype($groupsId) === 'string') {
93
+			$groupsId = [$groupsId];
94
+		}
77 95
 		switch (strtolower($operation)) {
78 96
 			case 'sum': $comp = $this->calcSum($team, $groupsId); break;
79 97
 			case 'avg': $comp = $this->calcSum($team, $groupsId)/count($groupsId); break;
@@ -95,21 +113,27 @@  discard block
 block discarded – undo
95 113
 	private function calcSum(Team $team, $groupsId) {
96 114
 		$sum = 0;
97 115
 		foreach ($groupsId as $id) {
98
-			if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][$this->what];
116
+			if (isset($team->groupResults[$id])) {
117
+				$sum += $team->groupResults[$id][$this->what];
118
+			}
99 119
 		}
100 120
 		return $sum;
101 121
 	}
102 122
 	private function calcMax(Team $team, $groupsId) {
103 123
 		$max = null;
104 124
 		foreach ($groupsId as $id) {
105
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) $max = $team->groupResults[$id][$this->what];
125
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) {
126
+				$max = $team->groupResults[$id][$this->what];
127
+			}
106 128
 		}
107 129
 		return $max;
108 130
 	}
109 131
 	private function calcMin(Team $team, $groupsId) {
110 132
 		$min = null;
111 133
 		foreach ($groupsId as $id) {
112
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) $min = $team->groupResults[$id][$this->what];
134
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) {
135
+				$min = $team->groupResults[$id][$this->what];
136
+			}
113 137
 		}
114 138
 		return $min;
115 139
 	}
Please login to merge, or discard this patch.
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/Teams.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
 					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
19 19
 					return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1);
20 20
 				});
21
-				break;}
21
+				break; }
22 22
 			case \TournamentGenerator\Constants::SCORE:{
23 23
 				uasort($teams, function($a, $b) use ($group) {
24 24
 					if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0;
25 25
 					return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
26 26
 				});
27
-				break;}
27
+				break; }
28 28
 		}
29 29
 
30 30
 		return $teams;
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
 					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
42 42
 					return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
43 43
 				});
44
-				break;}
44
+				break; }
45 45
 			case \TournamentGenerator\Constants::SCORE:{
46 46
 				uasort($teams, function($a, $b) use ($groupsIds) {
47 47
 					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
48 48
 					return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
49 49
 				});
50
-				break;}
50
+				break; }
51 51
 		}
52 52
 
53 53
 		return $teams;
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,19 +9,27 @@  discard block
 block discarded – undo
9 9
 {
10 10
 
11 11
 	public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) {
12
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
12
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
13
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
14
+		}
13 15
 
14 16
 		switch ($ordering) {
15 17
 			case \TournamentGenerator\Constants::POINTS:{
16 18
 				uasort($teams, function($a, $b) use ($group) {
17
-					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0;
18
-					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
19
+					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) {
20
+						return 0;
21
+					}
22
+					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) {
23
+						return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
24
+					}
19 25
 					return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1);
20 26
 				});
21 27
 				break;}
22 28
 			case \TournamentGenerator\Constants::SCORE:{
23 29
 				uasort($teams, function($a, $b) use ($group) {
24
-					if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0;
30
+					if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) {
31
+						return 0;
32
+					}
25 33
 					return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
26 34
 				});
27 35
 				break;}
@@ -30,21 +38,29 @@  discard block
 block discarded – undo
30 38
 		return $teams;
31 39
 	}
32 40
 	public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) {
33
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
41
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
42
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
43
+		}
34 44
 
35 45
 		$groupsIds = $round->getGroupsIds();
36 46
 
37 47
 		switch ($ordering) {
38 48
 			case \TournamentGenerator\Constants::POINTS:{
39 49
 				uasort($teams, function($a, $b) use ($groupsIds) {
40
-					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
41
-					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
50
+					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
51
+						return 0;
52
+					}
53
+					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) {
54
+						return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
55
+					}
42 56
 					return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
43 57
 				});
44 58
 				break;}
45 59
 			case \TournamentGenerator\Constants::SCORE:{
46 60
 				uasort($teams, function($a, $b) use ($groupsIds) {
47
-					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
61
+					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
62
+						return 0;
63
+					}
48 64
 					return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
49 65
 				});
50 66
 				break;}
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
@@ -66,70 +66,70 @@
 block discarded – undo
66 66
 		return $this->sumScore;
67 67
 	}
68 68
 
69
-	public function addWin(string $groupId = ''){
69
+	public function addWin(string $groupId = '') {
70 70
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
71 71
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
72 72
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
73 73
 		$this->groupResults[$groupId]['wins']++;
74 74
 		return $this;
75 75
 	}
76
-	public function removeWin(string $groupId = ''){
76
+	public function removeWin(string $groupId = '') {
77 77
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
78 78
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
79 79
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
80 80
 		$this->groupResults[$groupId]['wins']--;
81 81
 		return $this;
82 82
 	}
83
-	public function addDraw(string $groupId = ''){
83
+	public function addDraw(string $groupId = '') {
84 84
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
85 85
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
86 86
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
87 87
 		$this->groupResults[$groupId]['draws']++;
88 88
 		return $this;
89 89
 	}
90
-	public function removeDraw(string $groupId = ''){
90
+	public function removeDraw(string $groupId = '') {
91 91
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
92 92
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints;
93 93
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
94 94
 		$this->groupResults[$groupId]['draws']--;
95 95
 		return $this;
96 96
 	}
97
-	public function addLoss(string $groupId = ''){
97
+	public function addLoss(string $groupId = '') {
98 98
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
99 99
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
100 100
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
101 101
 		$this->groupResults[$groupId]['losses']++;
102 102
 		return $this;
103 103
 	}
104
-	public function removeLoss(string $groupId = ''){
104
+	public function removeLoss(string $groupId = '') {
105 105
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
106 106
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
107 107
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
108 108
 		$this->groupResults[$groupId]['losses']--;
109 109
 		return $this;
110 110
 	}
111
-	public function addSecond(string $groupId = ''){
111
+	public function addSecond(string $groupId = '') {
112 112
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
113 113
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
114 114
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
115 115
 		$this->groupResults[$groupId]['second']++;
116 116
 		return $this;
117 117
 	}
118
-	public function removeSecond(string $groupId = ''){
118
+	public function removeSecond(string $groupId = '') {
119 119
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
120 120
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
121 121
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
122 122
 		$this->groupResults[$groupId]['second']--;
123 123
 		return $this;
124 124
 	}
125
-	public function addThird(string $groupId = ''){
125
+	public function addThird(string $groupId = '') {
126 126
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
127 127
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
128 128
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
129 129
 		$this->groupResults[$groupId]['third']++;
130 130
 		return $this;
131 131
 	}
132
-	public function removeThird(string $groupId = ''){
132
+	public function removeThird(string $groupId = '') {
133 133
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
134 134
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
135 135
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
Please login to merge, or discard this patch.
Braces   +51 added lines, -17 removed lines patch added patch discarded remove patch
@@ -44,17 +44,23 @@  discard block
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	public function addGameWith(Team $team, Group $group) {
47
-		if (!isset($this->gamesWith[$group->id][$team->id])) $this->gamesWith[$group->id][$team->id] = 0;
47
+		if (!isset($this->gamesWith[$group->id][$team->id])) {
48
+			$this->gamesWith[$group->id][$team->id] = 0;
49
+		}
48 50
 		$this->gamesWith[$group->id][$team->id]++;
49 51
 		return $this;
50 52
 	}
51 53
 	public function addGroup(Group $group) {
52
-		if (!isset($this->games[$group->id])) $this->games[$group->id] = [];
54
+		if (!isset($this->games[$group->id])) {
55
+			$this->games[$group->id] = [];
56
+		}
53 57
 		return $this;
54 58
 	}
55 59
 	public function addGame(Game $game) {
56 60
 		$group = $game->getGroup();
57
-		if (!isset($this->games[$group->id])) $this->games[$group->id] = [];
61
+		if (!isset($this->games[$group->id])) {
62
+			$this->games[$group->id] = [];
63
+		}
58 64
 		$this->games[$group->id][] = $game;
59 65
 		return $this;
60 66
 	}
@@ -67,88 +73,116 @@  discard block
 block discarded – undo
67 73
 	}
68 74
 
69 75
 	public function addWin(string $groupId = ''){
70
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
76
+		if (!isset($this->groupResults[$groupId])) {
77
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
78
+		}
71 79
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
72 80
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
73 81
 		$this->groupResults[$groupId]['wins']++;
74 82
 		return $this;
75 83
 	}
76 84
 	public function removeWin(string $groupId = ''){
77
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
85
+		if (!isset($this->groupResults[$groupId])) {
86
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
87
+		}
78 88
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
79 89
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
80 90
 		$this->groupResults[$groupId]['wins']--;
81 91
 		return $this;
82 92
 	}
83 93
 	public function addDraw(string $groupId = ''){
84
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
94
+		if (!isset($this->groupResults[$groupId])) {
95
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
96
+		}
85 97
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
86 98
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
87 99
 		$this->groupResults[$groupId]['draws']++;
88 100
 		return $this;
89 101
 	}
90 102
 	public function removeDraw(string $groupId = ''){
91
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
103
+		if (!isset($this->groupResults[$groupId])) {
104
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
105
+		}
92 106
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints;
93 107
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
94 108
 		$this->groupResults[$groupId]['draws']--;
95 109
 		return $this;
96 110
 	}
97 111
 	public function addLoss(string $groupId = ''){
98
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
112
+		if (!isset($this->groupResults[$groupId])) {
113
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
114
+		}
99 115
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
100 116
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
101 117
 		$this->groupResults[$groupId]['losses']++;
102 118
 		return $this;
103 119
 	}
104 120
 	public function removeLoss(string $groupId = ''){
105
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
121
+		if (!isset($this->groupResults[$groupId])) {
122
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
123
+		}
106 124
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
107 125
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
108 126
 		$this->groupResults[$groupId]['losses']--;
109 127
 		return $this;
110 128
 	}
111 129
 	public function addSecond(string $groupId = ''){
112
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
130
+		if (!isset($this->groupResults[$groupId])) {
131
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
132
+		}
113 133
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
114 134
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
115 135
 		$this->groupResults[$groupId]['second']++;
116 136
 		return $this;
117 137
 	}
118 138
 	public function removeSecond(string $groupId = ''){
119
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
139
+		if (!isset($this->groupResults[$groupId])) {
140
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
141
+		}
120 142
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
121 143
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
122 144
 		$this->groupResults[$groupId]['second']--;
123 145
 		return $this;
124 146
 	}
125 147
 	public function addThird(string $groupId = ''){
126
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
148
+		if (!isset($this->groupResults[$groupId])) {
149
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
150
+		}
127 151
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
128 152
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
129 153
 		$this->groupResults[$groupId]['third']++;
130 154
 		return $this;
131 155
 	}
132 156
 	public function removeThird(string $groupId = ''){
133
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
157
+		if (!isset($this->groupResults[$groupId])) {
158
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
159
+		}
134 160
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
135 161
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
136 162
 		$this->groupResults[$groupId]['third']--;
137 163
 		return $this;
138 164
 	}
139 165
 	public function sumPoints(array $groupIds = []) {
140
-		if (count($groupIds) === 0) return $this->sumPoints;
166
+		if (count($groupIds) === 0) {
167
+			return $this->sumPoints;
168
+		}
141 169
 		$sum = 0;
142 170
 		foreach ($groupIds as $gid) {
143
-			if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['points'];
171
+			if (isset($this->groupResults[$gid])) {
172
+				$sum += $this->groupResults[$gid]['points'];
173
+			}
144 174
 		}
145 175
 		return $sum;
146 176
 	}
147 177
 	public function sumScore(array $groupIds = []) {
148
-		if (count($groupIds) === 0) return $this->sumScore;
178
+		if (count($groupIds) === 0) {
179
+			return $this->sumScore;
180
+		}
149 181
 		$sum = 0;
150 182
 		foreach ($groupIds as $gid) {
151
-			if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['score'];
183
+			if (isset($this->groupResults[$gid])) {
184
+				$sum += $this->groupResults[$gid]['score'];
185
+			}
152 186
 		}
153 187
 		return $sum;
154 188
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/Group.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 		return 'Group '.$this->name;
55 55
 	}
56 56
 
57
-	public function allowSkip(){
57
+	public function allowSkip() {
58 58
 		$this->generator->allowSkip();
59 59
 		return $this;
60 60
 	}
61
-	public function disallowSkip(){
61
+	public function disallowSkip() {
62 62
 		$this->generator->disallowSkip();
63 63
 		return $this;
64 64
 	}
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 		$this->games[] = $g;
195 195
 		return $g;
196 196
 	}
197
-	public function addGame(...$games){
197
+	public function addGame(...$games) {
198 198
 		foreach ($games as $key => $game) {
199 199
 			if (gettype($game) === 'array') {
200 200
 				unset($games[$key]);
201
-				$this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); }));
201
+				$this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); }));
202 202
 				continue;
203 203
 			}
204 204
 			if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.');
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		}
225 225
 		return $this;
226 226
 	}
227
-	public function isPlayed(){
227
+	public function isPlayed() {
228 228
 		foreach ($this->games as $game) {
229 229
 			if (!$game->isPlayed()) return false;
230 230
 		}
Please login to merge, or discard this patch.
Braces   +23 added lines, -9 removed lines patch added patch discarded remove patch
@@ -99,8 +99,11 @@  discard block
 block discarded – undo
99 99
 	public function getTeams($filters = []) {
100 100
 		$teams = $this->teams;
101 101
 
102
-		if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters];
103
-		elseif (gettype($filters) !== 'array') $filters = [];
102
+		if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) {
103
+			$filters = [$filters];
104
+		} elseif (gettype($filters) !== 'array') {
105
+			$filters = [];
106
+		}
104 107
 
105 108
 		// APPLY FILTERS
106 109
 		$filter = new Filter($this, $filters);
@@ -125,7 +128,9 @@  discard block
 block discarded – undo
125 128
 		return $t;
126 129
 	}
127 130
 	public function sortTeams($filters = [], $ordering = null) {
128
-		if (!isset($ordering)) $ordering = $this->ordering;
131
+		if (!isset($ordering)) {
132
+			$ordering = $this->ordering;
133
+		}
129 134
 		Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering);
130 135
 		return $this->getTeams($filters);
131 136
 	}
@@ -139,7 +144,9 @@  discard block
 block discarded – undo
139 144
 	}
140 145
 
141 146
 	public function setOrdering(string $ordering = \TournamentGenerator\Constants::POINTS) {
142
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering);
147
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
148
+			throw new \Exception('Unknown group ordering: '.$ordering);
149
+		}
143 150
 		$this->ordering = $ordering;
144 151
 		return $this;
145 152
 	}
@@ -171,8 +178,9 @@  discard block
 block discarded – undo
171 178
 	}
172 179
 	public function addProgressed(...$teams) {
173 180
 		foreach ($teams as $team) {
174
-			if ($team instanceOf Team) $this->progressed[] = $team->id;
175
-			elseif (gettype($team) === 'array') {
181
+			if ($team instanceOf Team) {
182
+				$this->progressed[] = $team->id;
183
+			} elseif (gettype($team) === 'array') {
176 184
 				$this->progressed = array_merge($this->progressed, array_filter($team, function($a) {
177 185
 					return ($a instanceof Team);
178 186
 				}));
@@ -201,7 +209,9 @@  discard block
 block discarded – undo
201 209
 				$this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); }));
202 210
 				continue;
203 211
 			}
204
-			if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.');
212
+			if (!$game instanceof Game) {
213
+				throw new \Exception('Trying to add game which is not instance of Game object.');
214
+			}
205 215
 			$this->games[] = $game;
206 216
 		}
207 217
 		return $this;
@@ -210,7 +220,9 @@  discard block
 block discarded – undo
210 220
 		return $this->games;
211 221
 	}
212 222
 	public function orderGames() {
213
-		if (count($this->games) <= 4) return $this->games;
223
+		if (count($this->games) <= 4) {
224
+			return $this->games;
225
+		}
214 226
 		$this->games = $this->generator->orderGames();
215 227
 		return $this->games;
216 228
 	}
@@ -226,7 +238,9 @@  discard block
 block discarded – undo
226 238
 	}
227 239
 	public function isPlayed(){
228 240
 		foreach ($this->games as $game) {
229
-			if (!$game->isPlayed()) return false;
241
+			if (!$game->isPlayed()) {
242
+				return false;
243
+			}
230 244
 		}
231 245
 		return true;
232 246
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/Filter.php 1 patch
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
 			if (gettype($filter) === 'array') {
26 26
 				$this->filterMulti($teams, $filter, $key);
27 27
 				continue;
28
-			}
29
-			elseif ($filter instanceof TeamFilter) {
28
+			} elseif ($filter instanceof TeamFilter) {
30 29
 				$teams = array_filter($teams, function($team) use ($filter) {return $filter->validate($team, $this->group->id, 'sum', $this->group); });
31 30
 				continue;
32 31
 			}
@@ -39,12 +38,18 @@  discard block
 block discarded – undo
39 38
 		switch (strtolower($how)) {
40 39
 			case 'and':
41 40
 				foreach ($teams as $tkey => $team) {
42
-					if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
41
+					if (!$this->filterAnd($team, $filters)) {
42
+						unset($teams[$tkey]);
43
+					}
44
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
43 45
 				}
44 46
 				return true;
45 47
 			case 'or':
46 48
 				foreach ($teams as $tkey => $team) {
47
-					if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
49
+					if (!$this->filterOr($team, $filters)) {
50
+						unset($teams[$tkey]);
51
+					}
52
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
48 53
 				}
49 54
 				return true;
50 55
 		}
@@ -56,19 +61,24 @@  discard block
 block discarded – undo
56 61
 			if (gettype($value) === 'array') {
57 62
 				switch (strtolower($key)) {
58 63
 					case 'and':
59
-						if ($this->filterAnd($team, $value)) return false;
64
+						if ($this->filterAnd($team, $value)) {
65
+							return false;
66
+						}
60 67
 						break;
61 68
 					case 'or':
62
-						if ($this->filterOr($team, $value)) return false;
69
+						if ($this->filterOr($team, $value)) {
70
+							return false;
71
+						}
63 72
 						break;
64 73
 					default:
65 74
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
66 75
 						break;
67 76
 				}
68 77
 				continue;
69
-			}
70
-			elseif ($value instanceof TeamFilter) {
71
-				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return false;
78
+			} elseif ($value instanceof TeamFilter) {
79
+				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) {
80
+					return false;
81
+				}
72 82
 				continue;
73 83
 			}
74 84
 			throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class');
@@ -80,19 +90,24 @@  discard block
 block discarded – undo
80 90
 			if (gettype($value) === 'array') {
81 91
 				switch (strtolower($key)) {
82 92
 					case 'and':
83
-						if ($this->filterAnd($team, $value)) return true;
93
+						if ($this->filterAnd($team, $value)) {
94
+							return true;
95
+						}
84 96
 						break;
85 97
 					case 'or':
86
-						if ($this->filterOr($team, $value)) return true;
98
+						if ($this->filterOr($team, $value)) {
99
+							return true;
100
+						}
87 101
 						break;
88 102
 					default:
89 103
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
90 104
 						break;
91 105
 				}
92 106
 				continue;
93
-			}
94
-			elseif ($value instanceof TeamFilter) {
95
-				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return true;
107
+			} elseif ($value instanceof TeamFilter) {
108
+				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) {
109
+					return true;
110
+				}
96 111
 				continue;
97 112
 			}
98 113
 			throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class');
Please login to merge, or discard this patch.
src/TournamentGenerator/Game.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -94,10 +94,10 @@
 block discarded – undo
94 94
 	}
95 95
 
96 96
 	/**
97
-	* $results = array (
98
-	* * team->id => team->score
99
-	* )
100
-	*/
97
+	 * $results = array (
98
+	 * * team->id => team->score
99
+	 * )
100
+	 */
101 101
 	public function setResults(array $results = []) {
102 102
 		if (count($this->results) === 0) $this->resetResults();
103 103
 		arsort($results);
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -66,11 +66,11 @@
 block discarded – undo
66 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));
67 67
 		return $this;
68 68
 	}
69
-	public function getTeams(){
69
+	public function getTeams() {
70 70
 		return $this->teams;
71 71
 	}
72
-	public function getTeamsIds(){
73
-		return array_map(function($a){ return $a->id; }, $this->teams);
72
+	public function getTeamsIds() {
73
+		return array_map(function($a) { return $a->id; }, $this->teams);
74 74
 	}
75 75
 	public function getTeam(string $id) {
76 76
 		foreach ($this->teams as $team) {
Please login to merge, or discard this 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(){
@@ -74,7 +82,9 @@  discard block
 block discarded – undo
74 82
 	}
75 83
 	public function getTeam(string $id) {
76 84
 		foreach ($this->teams as $team) {
77
-			if ($team->id === $id) return $team;
85
+			if ($team->id === $id) {
86
+				return $team;
87
+			}
78 88
 		}
79 89
 		return false;
80 90
 	}
@@ -85,13 +95,17 @@  discard block
 block discarded – undo
85 95
 	* )
86 96
 	*/
87 97
 	public function setResults(array $results = []) {
88
-		if (count($this->results) === 0) $this->resetResults();
98
+		if (count($this->results) === 0) {
99
+			$this->resetResults();
100
+		}
89 101
 		arsort($results);
90 102
 		$inGame = /** @scrutinizer ignore-call */ $this->group->getInGame();
91 103
 		$i = 1;
92 104
 		foreach ($results as $id => $score) {
93 105
 			$team = $this->getTeam($id);
94
-			if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"');
106
+			if ($team === false) {
107
+				throw new \Exception('Couldn\'t find team with id of "'.$id.'"');
108
+			}
95 109
 			$this->results[$team->id] = ['score' => $score];
96 110
 			$team->sumScore += $score;
97 111
 			$prev = prev($results);
@@ -118,13 +132,11 @@  discard block
 block discarded – undo
118 132
 			$this->drawIds[] = $team->id;
119 133
 			$team->addDraw($this->group->id);
120 134
 			$this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw'];
121
-		}
122
-		elseif ($i === 1) {
135
+		} elseif ($i === 1) {
123 136
 			$this->winId = $team->id;
124 137
 			$team->addWin($this->group->id);
125 138
 			$this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win'];
126
-		}
127
-		else {
139
+		} else {
128 140
 			$this->lossId = $team->id;
129 141
 			$team->addLoss($this->group->id);
130 142
 			$this->results[$team->id] += ['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.