Completed
Push — master ( a6547d...2340fb )
by Tomáš
02:43
created
src/TournamentGenerator/Team.php 1 patch
Braces   +60 added lines, -20 removed lines patch added patch discarded remove patch
@@ -53,20 +53,26 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 	public function getGroupResults($groupId = null) {
55 55
 		if (isset($groupId)) {
56
-			if (!isset($this->groupResults[$groupId])) throw new \Exception('Trying to get unexisting group results ('.$groupId.')');
56
+			if (!isset($this->groupResults[$groupId])) {
57
+				throw new \Exception('Trying to get unexisting group results ('.$groupId.')');
58
+			}
57 59
 			return $this->groupResults[$groupId];
58 60
 		}
59 61
 		return $this->groupResults;
60 62
 	}
61 63
 
62 64
 	public function addGameWith(Team $team, Group $group) {
63
-		if (!isset($this->gamesWith[$group->getId()][$team->getId()])) $this->gamesWith[$group->getId()][$team->getId()] = 0;
65
+		if (!isset($this->gamesWith[$group->getId()][$team->getId()])) {
66
+			$this->gamesWith[$group->getId()][$team->getId()] = 0;
67
+		}
64 68
 		$this->gamesWith[$group->getId()][$team->getId()]++;
65 69
 		return $this;
66 70
 	}
67 71
 	public function getGameWith(Team $team = null, Group $group = null) {
68 72
 		if (isset($group)) {
69
-			if (isset($team)) return $this->gamesWith[$group->getId()][$team->getId()];
73
+			if (isset($team)) {
74
+				return $this->gamesWith[$group->getId()][$team->getId()];
75
+			}
70 76
 			return $this->gamesWith[$group->getId()];
71 77
 		}
72 78
 		if (isset($team)) {
@@ -75,25 +81,35 @@  discard block
 block discarded – undo
75 81
 				$filter = array_filter($games, function($key) use ($team){
76 82
 					return $key === $team->getId();
77 83
 				}, ARRAY_FILTER_USE_KEY);
78
-				if (count($filter) > 0) $return[$id] = $filter;
84
+				if (count($filter) > 0) {
85
+					$return[$id] = $filter;
86
+				}
79 87
 			}
80 88
 			return $return;
81 89
 		}
82 90
 		return $this->gamesWith;
83 91
 	}
84 92
 	public function addGroup(Group $group) {
85
-		if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = [];
93
+		if (!isset($this->games[$group->getId()])) {
94
+			$this->games[$group->getId()] = [];
95
+		}
86 96
 		return $this;
87 97
 	}
88 98
 	public function addGame(Game $game) {
89 99
 		$group = $game->getGroup();
90
-		if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = [];
100
+		if (!isset($this->games[$group->getId()])) {
101
+			$this->games[$group->getId()] = [];
102
+		}
91 103
 		$this->games[$group->getId()][] = $game;
92 104
 		return $this;
93 105
 	}
94 106
 	public function getGames(Group $group = null, $groupId = null) {
95
-		if (isset($group) && isset($this->games[$group->getId()])) return $this->games[$group->getId()];
96
-		if (isset($groupId) && isset($this->games[$groupId])) return $this->games[$groupId];
107
+		if (isset($group) && isset($this->games[$group->getId()])) {
108
+			return $this->games[$group->getId()];
109
+		}
110
+		if (isset($groupId) && isset($this->games[$groupId])) {
111
+			return $this->games[$groupId];
112
+		}
97 113
 		return $this->games;
98 114
 	}
99 115
 
@@ -105,14 +121,18 @@  discard block
 block discarded – undo
105 121
 	}
106 122
 
107 123
 	public function addWin(string $groupId = ''){
108
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
124
+		if (!isset($this->groupResults[$groupId])) {
125
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
126
+		}
109 127
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getWinPoints();
110 128
 		$this->sumPoints += $this->groupResults[$groupId]['group']->getWinPoints();
111 129
 		$this->groupResults[$groupId]['wins']++;
112 130
 		return $this;
113 131
 	}
114 132
 	public function removeWin(string $groupId = ''){
115
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
133
+		if (!isset($this->groupResults[$groupId])) {
134
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
135
+		}
116 136
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getWinPoints();
117 137
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->getWinPoints();
118 138
 		$this->groupResults[$groupId]['wins']--;
@@ -120,14 +140,18 @@  discard block
 block discarded – undo
120 140
 	}
121 141
 
122 142
 	public function addDraw(string $groupId = ''){
123
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
143
+		if (!isset($this->groupResults[$groupId])) {
144
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
145
+		}
124 146
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getDrawPoints();
125 147
 		$this->sumPoints += $this->groupResults[$groupId]['group']->getDrawPoints();
126 148
 		$this->groupResults[$groupId]['draws']++;
127 149
 		return $this;
128 150
 	}
129 151
 	public function removeDraw(string $groupId = ''){
130
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
152
+		if (!isset($this->groupResults[$groupId])) {
153
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
154
+		}
131 155
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getDrawPoints();
132 156
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->getDrawPoints();
133 157
 		$this->groupResults[$groupId]['draws']--;
@@ -135,14 +159,18 @@  discard block
 block discarded – undo
135 159
 	}
136 160
 
137 161
 	public function addLoss(string $groupId = ''){
138
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
162
+		if (!isset($this->groupResults[$groupId])) {
163
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
164
+		}
139 165
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getLostPoints();
140 166
 		$this->sumPoints += $this->groupResults[$groupId]['group']->getLostPoints();
141 167
 		$this->groupResults[$groupId]['losses']++;
142 168
 		return $this;
143 169
 	}
144 170
 	public function removeLoss(string $groupId = ''){
145
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
171
+		if (!isset($this->groupResults[$groupId])) {
172
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
173
+		}
146 174
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getLostPoints();
147 175
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->getLostPoints();
148 176
 		$this->groupResults[$groupId]['losses']--;
@@ -150,14 +178,18 @@  discard block
 block discarded – undo
150 178
 	}
151 179
 
152 180
 	public function addSecond(string $groupId = ''){
153
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
181
+		if (!isset($this->groupResults[$groupId])) {
182
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
183
+		}
154 184
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getSecondPoints();
155 185
 		$this->sumPoints += $this->groupResults[$groupId]['group']->getSecondPoints();
156 186
 		$this->groupResults[$groupId]['second']++;
157 187
 		return $this;
158 188
 	}
159 189
 	public function removeSecond(string $groupId = ''){
160
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
190
+		if (!isset($this->groupResults[$groupId])) {
191
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
192
+		}
161 193
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getSecondPoints();
162 194
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->getSecondPoints();
163 195
 		$this->groupResults[$groupId]['second']--;
@@ -165,14 +197,18 @@  discard block
 block discarded – undo
165 197
 	}
166 198
 
167 199
 	public function addThird(string $groupId = ''){
168
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
200
+		if (!isset($this->groupResults[$groupId])) {
201
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
202
+		}
169 203
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->getThirdPoints();
170 204
 		$this->sumPoints += $this->groupResults[$groupId]['group']->getThirdPoints();
171 205
 		$this->groupResults[$groupId]['third']++;
172 206
 		return $this;
173 207
 	}
174 208
 	public function removeThird(string $groupId = ''){
175
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
209
+		if (!isset($this->groupResults[$groupId])) {
210
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
211
+		}
176 212
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->getThirdPoints();
177 213
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->getThirdPoints();
178 214
 		$this->groupResults[$groupId]['third']--;
@@ -180,7 +216,9 @@  discard block
 block discarded – undo
180 216
 	}
181 217
 
182 218
 	public function sumPoints(array $groupIds = []) {
183
-		if (count($groupIds) === 0) return $this->sumPoints;
219
+		if (count($groupIds) === 0) {
220
+			return $this->sumPoints;
221
+		}
184 222
 		$sum = 0;
185 223
 		foreach ($groupIds as $gid) {
186 224
 			$sum += $this->groupResults[$gid]['points'] ?? 0;
@@ -188,7 +226,9 @@  discard block
 block discarded – undo
188 226
 		return $sum;
189 227
 	}
190 228
 	public function sumScore(array $groupIds = []) {
191
-		if (count($groupIds) === 0) return $this->sumScore;
229
+		if (count($groupIds) === 0) {
230
+			return $this->sumScore;
231
+		}
192 232
 		$sum = 0;
193 233
 		foreach ($groupIds as $gid) {
194 234
 			$sum += $this->groupResults[$gid]['score'] ?? 0;
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->getDrawPoints(), '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->getWinPoints(), '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->getLostPoints(), '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/Progression.php 1 patch
Braces   +18 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,12 +38,20 @@  discard block
 block discarded – undo
38 38
 	}
39 39
 
40 40
 	public function progress(bool $blank = false) {
41
-		if ($this->progressed) return $this;
42
-		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
43
-		else $teams = $this->from->sortTeams(null, $this->filters);
41
+		if ($this->progressed) {
42
+			return $this;
43
+		}
44
+		if ($blank) {
45
+			$teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
46
+		} else {
47
+			$teams = $this->from->sortTeams(null, $this->filters);
48
+		}
44 49
 
45
-		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
46
-		else $next = $teams;
50
+		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) {
51
+			$next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
52
+		} else {
53
+			$next = $teams;
54
+		}
47 55
 
48 56
 		$i = 1;
49 57
 
@@ -51,12 +59,15 @@  discard block
 block discarded – undo
51 59
 			if ($blank) {
52 60
 				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team, $this->from, $this));
53 61
 				$i++;
62
+			} else {
63
+				$team->addPoints($this->from->getProgressPoints());
54 64
 			}
55
-			else $team->addPoints($this->from->getProgressPoints());
56 65
 		}
57 66
 
58 67
 		$this->from->addProgressed($next);
59
-		if (!$blank) $this->to->addTeam($next);
68
+		if (!$blank) {
69
+			$this->to->addTeam($next);
70
+		}
60 71
 		$this->progressed = true;
61 72
 		return $this;
62 73
 	}
Please login to merge, or discard this patch.