Completed
Push — master ( 2096e2...1f08e2 )
by Tomáš
02:41 queued 58s
created
src/classes/class_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') {
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -43,70 +43,70 @@
 block discarded – undo
43 43
 		return array_filter($this->groupResults[$groupId], function($k) { return $k !== 'group'; }, ARRAY_FILTER_USE_KEY);
44 44
 	}
45 45
 
46
-	public function addWin(string $groupId = ''){
46
+	public function addWin(string $groupId = '') {
47 47
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
48 48
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
49 49
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
50 50
 		$this->groupResults[$groupId]['wins']++;
51 51
 		return $this;
52 52
 	}
53
-	public function removeWin(string $groupId = ''){
53
+	public function removeWin(string $groupId = '') {
54 54
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
55 55
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
56 56
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
57 57
 		$this->groupResults[$groupId]['wins']--;
58 58
 		return $this;
59 59
 	}
60
-	public function addDraw(string $groupId = ''){
60
+	public function addDraw(string $groupId = '') {
61 61
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
62 62
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
63 63
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
64 64
 		$this->groupResults[$groupId]['draws']++;
65 65
 		return $this;
66 66
 	}
67
-	public function removeDraw(string $groupId = ''){
67
+	public function removeDraw(string $groupId = '') {
68 68
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
69 69
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints;
70 70
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
71 71
 		$this->groupResults[$groupId]['draws']--;
72 72
 		return $this;
73 73
 	}
74
-	public function addLoss(string $groupId = ''){
74
+	public function addLoss(string $groupId = '') {
75 75
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
76 76
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
77 77
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
78 78
 		$this->groupResults[$groupId]['losses']++;
79 79
 		return $this;
80 80
 	}
81
-	public function removeLoss(string $groupId = ''){
81
+	public function removeLoss(string $groupId = '') {
82 82
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
83 83
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
84 84
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
85 85
 		$this->groupResults[$groupId]['losses']--;
86 86
 		return $this;
87 87
 	}
88
-	public function addSecond(string $groupId = ''){
88
+	public function addSecond(string $groupId = '') {
89 89
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
90 90
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
91 91
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
92 92
 		$this->groupResults[$groupId]['second']++;
93 93
 		return $this;
94 94
 	}
95
-	public function removeSecond(string $groupId = ''){
95
+	public function removeSecond(string $groupId = '') {
96 96
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
97 97
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
98 98
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
99 99
 		$this->groupResults[$groupId]['second']--;
100 100
 		return $this;
101 101
 	}
102
-	public function addThird(string $groupId = ''){
102
+	public function addThird(string $groupId = '') {
103 103
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
104 104
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
105 105
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
106 106
 		$this->groupResults[$groupId]['third']++;
107 107
 		return $this;
108 108
 	}
109
-	public function removeThird(string $groupId = ''){
109
+	public function removeThird(string $groupId = '') {
110 110
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
111 111
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
112 112
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
Please login to merge, or discard this patch.
Braces   +30 added lines, -10 removed lines patch added patch discarded remove patch
@@ -44,70 +44,90 @@
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	public function addWin(string $groupId = ''){
47
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
47
+		if (!isset($this->groupResults[$groupId])) {
48
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
49
+		}
48 50
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
49 51
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
50 52
 		$this->groupResults[$groupId]['wins']++;
51 53
 		return $this;
52 54
 	}
53 55
 	public function removeWin(string $groupId = ''){
54
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
56
+		if (!isset($this->groupResults[$groupId])) {
57
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
58
+		}
55 59
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
56 60
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
57 61
 		$this->groupResults[$groupId]['wins']--;
58 62
 		return $this;
59 63
 	}
60 64
 	public function addDraw(string $groupId = ''){
61
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
65
+		if (!isset($this->groupResults[$groupId])) {
66
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
67
+		}
62 68
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
63 69
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
64 70
 		$this->groupResults[$groupId]['draws']++;
65 71
 		return $this;
66 72
 	}
67 73
 	public function removeDraw(string $groupId = ''){
68
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
74
+		if (!isset($this->groupResults[$groupId])) {
75
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
76
+		}
69 77
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints;
70 78
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
71 79
 		$this->groupResults[$groupId]['draws']--;
72 80
 		return $this;
73 81
 	}
74 82
 	public function addLoss(string $groupId = ''){
75
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
83
+		if (!isset($this->groupResults[$groupId])) {
84
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
85
+		}
76 86
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
77 87
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
78 88
 		$this->groupResults[$groupId]['losses']++;
79 89
 		return $this;
80 90
 	}
81 91
 	public function removeLoss(string $groupId = ''){
82
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
92
+		if (!isset($this->groupResults[$groupId])) {
93
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
94
+		}
83 95
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
84 96
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
85 97
 		$this->groupResults[$groupId]['losses']--;
86 98
 		return $this;
87 99
 	}
88 100
 	public function addSecond(string $groupId = ''){
89
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
101
+		if (!isset($this->groupResults[$groupId])) {
102
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
103
+		}
90 104
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
91 105
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
92 106
 		$this->groupResults[$groupId]['second']++;
93 107
 		return $this;
94 108
 	}
95 109
 	public function removeSecond(string $groupId = ''){
96
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
110
+		if (!isset($this->groupResults[$groupId])) {
111
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
112
+		}
97 113
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
98 114
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
99 115
 		$this->groupResults[$groupId]['second']--;
100 116
 		return $this;
101 117
 	}
102 118
 	public function addThird(string $groupId = ''){
103
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
119
+		if (!isset($this->groupResults[$groupId])) {
120
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
121
+		}
104 122
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
105 123
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
106 124
 		$this->groupResults[$groupId]['third']++;
107 125
 		return $this;
108 126
 	}
109 127
 	public function removeThird(string $groupId = ''){
110
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
128
+		if (!isset($this->groupResults[$groupId])) {
129
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
130
+		}
111 131
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
112 132
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
113 133
 		$this->groupResults[$groupId]['third']--;
Please login to merge, or discard this patch.
src/classes/class_tournament.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 	private $allowSkip = false;
22 22
 
23
-	function __construct(string $name = ''){
23
+	function __construct(string $name = '') {
24 24
 		$this->name = $name;
25 25
 	}
26 26
 	public function __toString() {
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
 	public function getCategoryWait() {
56 56
 		return $this->expectedCategoryWait;
57 57
 	}
58
-	public function getTournamentTime(){
58
+	public function getTournamentTime() {
59 59
 		$games = count($this->getGames());
60 60
 		return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait;
61 61
 	}
62 62
 
63
-	public function allowSkip(){
63
+	public function allowSkip() {
64 64
 		$this->allowSkip = true;
65 65
 		return $this;
66 66
 	}
67
-	public function disallowSkip(){
67
+	public function disallowSkip() {
68 68
 		$this->allowSkip = false;
69 69
 		return $this;
70 70
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		return $this->allowSkip;
77 77
 	}
78 78
 
79
-	public function addCategory(Category ...$categories){
79
+	public function addCategory(Category ...$categories) {
80 80
 		foreach ($categories as $category) {
81 81
 			if ($category instanceof Category) $this->categories[] = $category;
82 82
 			else throw new \Exception('Trying to add category which is not an instance of the Category class.');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 	public function addTeam(...$teams) {
119 119
 		foreach ($teams as $team) {
120
-			if ($team instanceof Team)  {
120
+			if ($team instanceof Team) {
121 121
 				$this->teams[] = $team;
122 122
 			}
123 123
 			elseif (gettype($team) === 'array') {
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 						if ($a->sumPoints === $b->sumPoints) return ($a->sumScore > $b->sumScore ? -1 : 1);
154 154
 						return ($a->sumPoints > $b->sumPoints ? -1 : 1);
155 155
 					});
156
-					break;}
156
+					break; }
157 157
 				case SCORE:{
158 158
 					uasort($this->teams, function($a, $b) {
159 159
 						if ($a->sumScore === $b->sumScore) return 0;
160 160
 						return ($a->sumScore > $b->sumScore ? -1 : 1);
161 161
 					});
162
-					break;}
162
+					break; }
163 163
 			}
164 164
 		}
165 165
 		return $this->teams;
Please login to merge, or discard this patch.
Braces   +45 added lines, -26 removed lines patch added patch discarded remove patch
@@ -78,8 +78,11 @@  discard block
 block discarded – undo
78 78
 
79 79
 	public function addCategory(Category ...$categories){
80 80
 		foreach ($categories as $category) {
81
-			if ($category instanceof Category) $this->categories[] = $category;
82
-			else throw new \Exception('Trying to add category which is not an instance of the Category class.');
81
+			if ($category instanceof Category) {
82
+				$this->categories[] = $category;
83
+			} else {
84
+				throw new \Exception('Trying to add category which is not an instance of the Category class.');
85
+			}
83 86
 		}
84 87
 		return $this;
85 88
 	}
@@ -94,8 +97,11 @@  discard block
 block discarded – undo
94 97
 
95 98
 	public function addRound(Round ...$rounds) {
96 99
 		foreach ($rounds as $round) {
97
-			if ($round instanceof Round) $this->rounds[] = $round;
98
-			else throw new \Exception('Trying to add round which is not an instance of the Round class.');
100
+			if ($round instanceof Round) {
101
+				$this->rounds[] = $round;
102
+			} else {
103
+				throw new \Exception('Trying to add round which is not an instance of the Round class.');
104
+			}
99 105
 		}
100 106
 		return $this;
101 107
 	}
@@ -119,13 +125,15 @@  discard block
 block discarded – undo
119 125
 		foreach ($teams as $team) {
120 126
 			if ($team instanceof Team)  {
121 127
 				$this->teams[] = $team;
122
-			}
123
-			elseif (gettype($team) === 'array') {
128
+			} elseif (gettype($team) === 'array') {
124 129
 				foreach ($team as $team2) {
125
-					if ($team2 instanceof Team) $this->teams[] = $team2;
130
+					if ($team2 instanceof Team) {
131
+						$this->teams[] = $team2;
132
+					}
126 133
 				}
134
+			} else {
135
+				throw new \Exception('Trying to add team which is not an instance of Team class');
127 136
 			}
128
-			else throw new \Exception('Trying to add team which is not an instance of Team class');
129 137
 		}
130 138
 		return $this;
131 139
 	}
@@ -149,14 +157,20 @@  discard block
 block discarded – undo
149 157
 			switch ($ordering) {
150 158
 				case POINTS:{
151 159
 					uasort($this->teams, function($a, $b) {
152
-						if ($a->sumPoints === $b->sumPoints && $a->sumScore === $b->sumScore) return 0;
153
-						if ($a->sumPoints === $b->sumPoints) return ($a->sumScore > $b->sumScore ? -1 : 1);
160
+						if ($a->sumPoints === $b->sumPoints && $a->sumScore === $b->sumScore) {
161
+							return 0;
162
+						}
163
+						if ($a->sumPoints === $b->sumPoints) {
164
+							return ($a->sumScore > $b->sumScore ? -1 : 1);
165
+						}
154 166
 						return ($a->sumPoints > $b->sumPoints ? -1 : 1);
155 167
 					});
156 168
 					break;}
157 169
 				case SCORE:{
158 170
 					uasort($this->teams, function($a, $b) {
159
-						if ($a->sumScore === $b->sumScore) return 0;
171
+						if ($a->sumScore === $b->sumScore) {
172
+							return 0;
173
+						}
160 174
 						return ($a->sumScore > $b->sumScore ? -1 : 1);
161 175
 					});
162 176
 					break;}
@@ -175,7 +189,9 @@  discard block
 block discarded – undo
175 189
 
176 190
 	public function splitTeams(...$wheres) {
177 191
 
178
-		if (count($wheres) === 0) $wheres = array_merge($this->getRounds(), $this->getCategories());
192
+		if (count($wheres) === 0) {
193
+			$wheres = array_merge($this->getRounds(), $this->getCategories());
194
+		}
179 195
 
180 196
 		foreach ($wheres as $key => $value) {
181 197
 			if (gettype($value) === 'array') {
@@ -190,10 +206,13 @@  discard block
 block discarded – undo
190 206
 		while (count($teams) > 0) {
191 207
 			foreach ($wheres as $where) {
192 208
 				if ($where instanceof Round) {
193
-					if (count($teams) > 0) $where->addTeam(array_shift($teams));
194
-				}
195
-				elseif ($where instanceof Category) {
196
-					if (count($teams) > 0) $where->addTeam(array_shift($teams));
209
+					if (count($teams) > 0) {
210
+						$where->addTeam(array_shift($teams));
211
+					}
212
+				} elseif ($where instanceof Category) {
213
+					if (count($teams) > 0) {
214
+						$where->addTeam(array_shift($teams));
215
+					}
197 216
 				}
198 217
 			}
199 218
 		}
@@ -209,8 +228,7 @@  discard block
 block discarded – undo
209 228
 			foreach ($this->categories as $category) {
210 229
 				$games = array_merge($games, $category->genGamesSimulate());
211 230
 			}
212
-		}
213
-		elseif (count($this->rounds) > 0) {
231
+		} elseif (count($this->rounds) > 0) {
214 232
 			foreach ($this->rounds as $round) {
215 233
 				$games = array_merge($games, $round->genGames());
216 234
 				$round->simulate()->progressBlank();
@@ -218,11 +236,12 @@  discard block
 block discarded – undo
218 236
 			foreach ($this->rounds as $round) {
219 237
 				$round->resetGames();
220 238
 			}
221
-		}
222
-		else {
239
+		} else {
223 240
 			throw new \Exception('There are no rounds or categories to simulate games from.');
224 241
 		}
225
-		if ($returnTime) return $this->getTournamentTime();
242
+		if ($returnTime) {
243
+			return $this->getTournamentTime();
244
+		}
226 245
 		return $games;
227 246
 	}
228 247
 	public function genGamesSimulateReal(bool $returnTime = false) {
@@ -231,18 +250,18 @@  discard block
 block discarded – undo
231 250
 			foreach ($this->categories as $category) {
232 251
 				$games = array_merge($games, $category->genGamesSimulate());
233 252
 			}
234
-		}
235
-		elseif (count($this->rounds) > 0) {
253
+		} elseif (count($this->rounds) > 0) {
236 254
 			foreach ($this->rounds as $round) {
237 255
 				$games = array_merge($games, $round->genGames());
238 256
 				$round->simulate();
239 257
 				$round->progress();
240 258
 			}
241
-		}
242
-		else {
259
+		} else {
243 260
 			throw new \Exception('There are no rounds or categories to simulate games from.');
244 261
 		}
245
-		if ($returnTime) return $this->getTournamentTime();
262
+		if ($returnTime) {
263
+			return $this->getTournamentTime();
264
+		}
246 265
 		return $games;
247 266
 	}
248 267
 
Please login to merge, or discard this patch.