Completed
Branch master (0e4a87)
by Tomáš
03:29 queued 01:30
created
src/classes/class_tournament.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 	private $allowSkip = false;
24 24
 
25
-	function __construct(string $name = ''){
25
+	function __construct(string $name = '') {
26 26
 		$this->name = $name;
27 27
 	}
28 28
 	public function __toString() {
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
 	public function getCategoryWait() {
58 58
 		return $this->expectedCategoryWait;
59 59
 	}
60
-	public function getTournamentTime(){
60
+	public function getTournamentTime() {
61 61
 		$games = count($this->getGames());
62 62
 		return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait;
63 63
 	}
64 64
 
65
-	public function allowSkip(){
65
+	public function allowSkip() {
66 66
 		$this->allowSkip = true;
67 67
 		return $this;
68 68
 	}
69
-	public function disallowSkip(){
69
+	public function disallowSkip() {
70 70
 		$this->allowSkip = false;
71 71
 		return $this;
72 72
 	}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		return $this->allowSkip;
79 79
 	}
80 80
 
81
-	public function addCategory(Category ...$categories){
81
+	public function addCategory(Category ...$categories) {
82 82
 		foreach ($categories as $category) {
83 83
 			if ($category instanceof Category) $this->categories[] = $category;
84 84
 			else throw new \Exception('Trying to add category which is not an instance of the Category class.');
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
 	public function addTeam(...$teams) {
121 121
 		foreach ($teams as $team) {
122
-			if ($team instanceof Team)  {
122
+			if ($team instanceof Team) {
123 123
 				$this->teams[] = $team;
124 124
 			}
125 125
 			elseif (gettype($team) === 'array') {
Please login to merge, or discard this patch.
src/classes/class_generator.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 		$this->group = $group;
20 20
 	}
21 21
 
22
-	public function allowSkip(){
22
+	public function allowSkip() {
23 23
 		$this->allowSkip = true;
24 24
 		return $this;
25 25
 	}
26
-	public function disallowSkip(){
26
+	public function disallowSkip() {
27 27
 		$this->allowSkip = false;
28 28
 		return $this;
29 29
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 
48 48
 	public function setInGame(int $inGame) {
49
-		if ($inGame < 2 ||  $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
49
+		if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
50 50
 		$this->inGame = $inGame;
51 51
 		return $this;
52 52
 	}
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
 		switch ($this->type) {
68 68
 			case R_R:{
69 69
 					$this->group->addGame($this->r_rGames());
70
-				break;}
70
+				break; }
71 71
 			case TWO_TWO:
72 72
 				$teams = $this->group->getTeams();
73 73
 				$discard = [];
74 74
 				shuffle($teams);
75 75
 				$count = count($teams);
76
-				while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); }
76
+				while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); }
77 77
 
78 78
 				while (count($teams) > 0) {
79 79
 					$tInGame = [];
80
-					for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); }
80
+					for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); }
81 81
 					$this->group->game($tInGame);
82 82
 				}
83 83
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 					}
124 124
 					$games = array_merge($games, $gamesTemp);
125 125
 				}
126
-				break;}
126
+				break; }
127 127
 			case 4:{
128 128
 				$teamsB = $teams;
129 129
 				$lockedTeam1 = array_shift($teamsB);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 					$lockedTeam1 = array_shift($teamsB);
141 141
 				}
142 142
 				$games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this->group);
143
-				break;}
143
+				break; }
144 144
 		}
145 145
 		return $games;
146 146
 	}
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 			// CYCLE 1
173 173
 			// TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4)
174 174
 			foreach ($games as $key => $game) {
175
-				if ($this->orderCheckTeamsVal($game, $teams, [4,5,6,7])) {
176
-					$this->moveCalculatedGames($game,$teams);
175
+				if ($this->orderCheckTeamsVal($game, $teams, [4, 5, 6, 7])) {
176
+					$this->moveCalculatedGames($game, $teams);
177 177
 					unset($games[$key]);
178 178
 					$found = true;
179 179
 					break;
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 			// CYCLE 2
185 185
 			// ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7)
186 186
 			foreach ($games as $key => $game) {
187
-				if ($this->orderCheckTeamsVal($game, $teams, [6,7])) {
188
-					$this->moveCalculatedGames($game,$teams);
187
+				if ($this->orderCheckTeamsVal($game, $teams, [6, 7])) {
188
+					$this->moveCalculatedGames($game, $teams);
189 189
 					unset($games[$key]);
190 190
 					$found = true;
191 191
 					break;
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
198 198
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
199 199
 			foreach ($games as $key => $game) {
200
-				if ($this->orderCheckTeamsVal($game, $teams, [7], [1,2,3])) {
201
-					$this->moveCalculatedGames($game,$teams);
200
+				if ($this->orderCheckTeamsVal($game, $teams, [7], [1, 2, 3])) {
201
+					$this->moveCalculatedGames($game, $teams);
202 202
 					unset($games[$key]);
203 203
 					$found = true;
204 204
 					break;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
211 211
 			foreach ($games as $key => $game) {
212 212
 				if ($this->orderCheckTeamsVal($game, $teams, [7])) {
213
-					$this->moveCalculatedGames($game,$teams);
213
+					$this->moveCalculatedGames($game, $teams);
214 214
 					unset($games[$key]);
215 215
 					$found = true;
216 216
 					break;
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 			// CYCLE 5
222 222
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
223 223
 			foreach ($games as $key => $game) {
224
-				if ($this->orderCheckTeamsVal($game, $teams, [], [1,2,3])) {
225
-					$this->moveCalculatedGames($game,$teams);
224
+				if ($this->orderCheckTeamsVal($game, $teams, [], [1, 2, 3])) {
225
+					$this->moveCalculatedGames($game, $teams);
226 226
 					unset($games[$key]);
227 227
 					$found = true;
228 228
 					break;
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 
233 233
 			// CYCLE 6
234 234
 			// FIRST AVAILABLE GAME
235
-			$this->moveCalculatedGames(array_shift($games),$teams);
235
+			$this->moveCalculatedGames(array_shift($games), $teams);
236 236
 		}
237 237
 
238 238
 		return $this->games;
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 	public static function circle_genGames2(array $teams = [], Group $group = null) {
284 284
 		$bracket = []; // ARRAY OF GAMES
285 285
 
286
-		if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
286
+		if (count($teams)%2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
287 287
 
288 288
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
289 289
 
290
-		for ($i=0; $i < count($teams)-1; $i++) {
290
+		for ($i = 0; $i < count($teams)-1; $i++) {
291 291
 			$bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND
292 292
 
293 293
 			$teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 
302 302
 		$bracket = [];
303 303
 
304
-		for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
304
+		for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
305 305
 
306 306
 			$home = $teams[$i];
307 307
 			$reverse = array_reverse($teams);
Please login to merge, or discard this patch.
src/classes/class_game.php 1 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.
src/classes/class_group.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 		return 'Group '.$this->name;
58 58
 	}
59 59
 
60
-	public function allowSkip(){
60
+	public function allowSkip() {
61 61
 		$this->generator->allowSkip();
62 62
 		return $this;
63 63
 	}
64
-	public function disallowSkip(){
64
+	public function disallowSkip() {
65 65
 		$this->generator->disallowSkip();
66 66
 		return $this;
67 67
 	}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
 	public function addTeam(...$teams) {
77 77
 		foreach ($teams as $team) {
78
-			if ($team instanceof Team)  {
78
+			if ($team instanceof Team) {
79 79
 				$this->teams[] = $team;
80 80
 				$team->groupResults[$this->id] = [
81 81
 					'group' => $this,
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
 					if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1);
170 170
 					return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1);
171 171
 				});
172
-				break;}
172
+				break; }
173 173
 			case SCORE:{
174 174
 				usort($this->teams, function($a, $b) {
175 175
 					if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0;
176 176
 					return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1);
177 177
 				});
178
-				break;}
178
+				break; }
179 179
 		}
180 180
 		return $this->getTeams($filters);
181 181
 	}
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		$this->games[] = $g;
307 307
 		return $g;
308 308
 	}
309
-	public function addGame(...$games){
309
+	public function addGame(...$games) {
310 310
 		foreach ($games as $key => $game) {
311 311
 			if (gettype($game) === 'array') {
312 312
 				unset($games[$key]);
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		}
351 351
 		return $this;
352 352
 	}
353
-	public function isPlayed(){
353
+	public function isPlayed() {
354 354
 		foreach ($this->games as $game) {
355 355
 			if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false;
356 356
 		}
Please login to merge, or discard this patch.
src/classes/class_round.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 		return $this->name;
24 24
 	}
25 25
 
26
-	public function addGroup(Group ...$groups){
26
+	public function addGroup(Group ...$groups) {
27 27
 		foreach ($groups as $group) {
28 28
 			if ($group instanceof Group) $this->groups[] = $group;
29 29
 			else throw new \Exception('Trying to add group which is not an instance of Group class.');
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		$this->groups[] = $g->setSkip($this->allowSkip);
36 36
 		return $g;
37 37
 	}
38
-	public function getGroups(){
38
+	public function getGroups() {
39 39
 		$this->orderGroups();
40 40
 		return $this->groups;
41 41
 	}
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
 		return array_map(function($a) { return $a->id; }, $this->groups);
45 45
 	}
46 46
 	public function orderGroups() {
47
-		usort($this->groups, function($a, $b){
48
-			return $a->order - $b->order;
47
+		usort($this->groups, function($a, $b) {
48
+			return $a->order-$b->order;
49 49
 		});
50 50
 	}
51 51
 
52
-	public function allowSkip(){
52
+	public function allowSkip() {
53 53
 		$this->allowSkip = true;
54 54
 		return $this;
55 55
 	}
56
-	public function disallowSkip(){
56
+	public function disallowSkip() {
57 57
 		$this->allowSkip = false;
58 58
 		return $this;
59 59
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		return $this->allowSkip;
66 66
 	}
67 67
 
68
-	public function genGames(){
68
+	public function genGames() {
69 69
 		$g = 0;
70 70
 		foreach ($this->groups as $group) {
71 71
 			$group->genGames();
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	public function getGames() {
77 77
 		return $this->games;
78 78
 	}
79
-	public function isPlayed(){
79
+	public function isPlayed() {
80 80
 		foreach ($this->groups as $group) {
81 81
 			if (!$group->isPlayed()) return false;
82 82
 		}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
 	public function addTeam(...$teams) {
87 87
 		foreach ($teams as $team) {
88
-			if ($team instanceof Team)  {
88
+			if ($team instanceof Team) {
89 89
 				$this->teams[] = $team;
90 90
 			}
91 91
 			elseif (gettype($team) === 'array') {
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
136 136
 					return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
137 137
 				});
138
-				break;}
138
+				break; }
139 139
 			case SCORE:{
140 140
 				uasort($this->teams, function($a, $b) use ($groupsIds) {
141 141
 					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
142 142
 					return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
143 143
 				});
144
-				break;}
144
+				break; }
145 145
 		}
146 146
 		return $this->teams;
147 147
 	}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		return $this;
171 171
 	}
172 172
 
173
-	public function progress(bool $blank = false){
173
+	public function progress(bool $blank = false) {
174 174
 		foreach ($this->groups as $group) {
175 175
 			$group->progress($blank);
176 176
 		}
Please login to merge, or discard this patch.
src/classes/class_team.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -59,70 +59,70 @@
 block discarded – undo
59 59
 		return $this;
60 60
 	}
61 61
 
62
-	public function addWin(string $groupId = ''){
62
+	public function addWin(string $groupId = '') {
63 63
 		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
64 64
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
65 65
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
66 66
 		$this->groupResults[$groupId]['wins']++;
67 67
 		return $this;
68 68
 	}
69
-	public function removeWin(string $groupId = ''){
69
+	public function removeWin(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 addDraw(string $groupId = ''){
76
+	public function addDraw(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']->drawPoints;
79 79
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
80 80
 		$this->groupResults[$groupId]['draws']++;
81 81
 		return $this;
82 82
 	}
83
-	public function removeDraw(string $groupId = ''){
83
+	public function removeDraw(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']->drawPointsPoints;
86 86
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
87 87
 		$this->groupResults[$groupId]['draws']--;
88 88
 		return $this;
89 89
 	}
90
-	public function addLoss(string $groupId = ''){
90
+	public function addLoss(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']->lostPoints;
93 93
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
94 94
 		$this->groupResults[$groupId]['losses']++;
95 95
 		return $this;
96 96
 	}
97
-	public function removeLoss(string $groupId = ''){
97
+	public function removeLoss(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 addSecond(string $groupId = ''){
104
+	public function addSecond(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']->secondPoints;
107 107
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
108 108
 		$this->groupResults[$groupId]['second']++;
109 109
 		return $this;
110 110
 	}
111
-	public function removeSecond(string $groupId = ''){
111
+	public function removeSecond(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 addThird(string $groupId = ''){
118
+	public function addThird(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']->thirdPoints;
121 121
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
122 122
 		$this->groupResults[$groupId]['third']++;
123 123
 		return $this;
124 124
 	}
125
-	public function removeThird(string $groupId = ''){
125
+	public function removeThird(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;
Please login to merge, or discard this patch.