Passed
Push — master ( 0e4a87...bf2039 )
by Tomáš
01:54
created
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
 		foreach ($this->groups as $group) {
70 70
 			$group->genGames();
71 71
 			$this->games = array_merge($this->games, $group->orderGames());
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	public function getGames() {
76 76
 		return $this->games;
77 77
 	}
78
-	public function isPlayed(){
78
+	public function isPlayed() {
79 79
 		foreach ($this->groups as $group) {
80 80
 			if (!$group->isPlayed()) return false;
81 81
 		}
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 	public function addTeam(...$teams) {
86 86
 		foreach ($teams as $team) {
87
-			if ($team instanceof Team)  {
87
+			if ($team instanceof Team) {
88 88
 				$this->teams[] = $team;
89 89
 			}
90 90
 			elseif (gettype($team) === 'array') {
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
 					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
134 134
 					return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
135 135
 				});
136
-				break;}
136
+				break; }
137 137
 			case SCORE:{
138 138
 				uasort($this->teams, function($a, $b) use ($groupsIds) {
139 139
 					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
140 140
 					return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
141 141
 				});
142
-				break;}
142
+				break; }
143 143
 		}
144 144
 		return $this->teams;
145 145
 	}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		return $this;
169 169
 	}
170 170
 
171
-	public function progress(bool $blank = false){
171
+	public function progress(bool $blank = false) {
172 172
 		foreach ($this->groups as $group) {
173 173
 			$group->progress($blank);
174 174
 		}
Please login to merge, or discard this patch.
src/classes/tournament_presets/class_2R2G.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
 
51 51
 		$this->splitTeams($round1);
52 52
 
53
-		if (count($this->getTeams()) % 4 == 2) {
53
+		if (count($this->getTeams())%4 == 2) {
54 54
 			$group_top = $round2->group([
55 55
 				'name' => 'TOP',
56 56
 				'type' => \TournamentGenerator\TWO_TWO
Please login to merge, or discard this patch.
src/classes/class_generator.php 2 patches
Spacing   +11 added lines, -11 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 \TournamentGenerator\R_R:{
69 69
 					$this->group->addGame($this->r_rGames());
70
-				break;}
70
+				break; }
71 71
 			case \TournamentGenerator\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 \TournamentGenerator\Game(array_merge([$lockedTeam1], $teamsB), $this->group);
143
-				break;}
143
+				break; }
144 144
 		}
145 145
 		return $games;
146 146
 	}
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
 	public static function circle_genGames2(array $teams = [], Group $group) {
156 156
 		$bracket = []; // ARRAY OF GAMES
157 157
 
158
-		if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
158
+		if (count($teams)%2 != 0) $teams[] = \TournamentGenerator\DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
159 159
 
160 160
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
161 161
 
162
-		for ($i=0; $i < count($teams)-1; $i++) {
162
+		for ($i = 0; $i < count($teams)-1; $i++) {
163 163
 			$bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND
164 164
 
165 165
 			$teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 
174 174
 		$bracket = [];
175 175
 
176
-		for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
176
+		for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS
177 177
 
178 178
 			$home = $teams[$i];
179 179
 			$reverse = array_reverse($teams);
Please login to merge, or discard this patch.
Braces   +30 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,8 +37,11 @@  discard block
 block discarded – undo
37 37
 
38 38
 
39 39
 	public function setType(/** @scrutinizer ignore-all */ string $type = \TournamentGenerator\R_R) {
40
-		if (in_array($type, \TournamentGenerator\groupTypes)) $this->type = $type;
41
-		else throw new \Exception('Unknown group type: '.$type);
40
+		if (in_array($type, \TournamentGenerator\groupTypes)) {
41
+			$this->type = $type;
42
+		} else {
43
+			throw new \Exception('Unknown group type: '.$type);
44
+		}
42 45
 		return $this;
43 46
 	}
44 47
 	public function getType() {
@@ -46,7 +49,9 @@  discard block
 block discarded – undo
46 49
 	}
47 50
 
48 51
 	public function setInGame(int $inGame) {
49
-		if ($inGame < 2 ||  $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
52
+		if ($inGame < 2 ||  $inGame > 4) {
53
+			throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
54
+		}
50 55
 		$this->inGame = $inGame;
51 56
 		return $this;
52 57
 	}
@@ -55,7 +60,9 @@  discard block
 block discarded – undo
55 60
 	}
56 61
 
57 62
 	public function setMaxSize(int $maxSize) {
58
-		if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
63
+		if ($maxSize < 2) {
64
+			throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
65
+		}
59 66
 		$this->maxSize = $maxSize;
60 67
 		return $this;
61 68
 	}
@@ -81,7 +88,9 @@  discard block
 block discarded – undo
81 88
 					$this->group->game($tInGame);
82 89
 				}
83 90
 
84
-				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'));
91
+				if (count($discard) > 0 && !$this->allowSkip) {
92
+					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'));
93
+				}
85 94
 				break;
86 95
 			case \TournamentGenerator\COND_SPLIT:
87 96
 				$games = [];
@@ -96,19 +105,24 @@  discard block
 block discarded – undo
96 105
 					while ($g > 0) {
97 106
 						foreach ($games as $key => $group) {
98 107
 							$this->group->addGame(array_shift($games[$key]));
99
-							if (count($games[$key]) === 0) unset($games[$key]);
108
+							if (count($games[$key]) === 0) {
109
+								unset($games[$key]);
110
+							}
100 111
 							$g--;
101 112
 						}
102 113
 					}
114
+				} else {
115
+					$this->group->addGame($this->r_rGames());
103 116
 				}
104
-				else $this->group->addGame($this->r_rGames());
105 117
 				break;
106 118
 		}
107 119
 		return $this->group->getGames();
108 120
 	}
109 121
 	public function r_rGames(array $teams = []) {
110 122
 		$games = [];
111
-		if (count($teams) === 0) $teams = $this->group->getTeams();
123
+		if (count($teams) === 0) {
124
+			$teams = $this->group->getTeams();
125
+		}
112 126
 		switch ($this->inGame) {
113 127
 			case 2:
114 128
 				$games = Generator::circle_genGames2($teams, $this->group);
@@ -155,7 +169,10 @@  discard block
 block discarded – undo
155 169
 	public static function circle_genGames2(array $teams = [], Group $group) {
156 170
 		$bracket = []; // ARRAY OF GAMES
157 171
 
158
-		if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
172
+		if (count($teams) % 2 != 0) {
173
+			$teams[] = \TournamentGenerator\DUMMY_TEAM;
174
+		}
175
+		// IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
159 176
 
160 177
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
161 178
 
@@ -179,7 +196,10 @@  discard block
 block discarded – undo
179 196
 			$reverse = array_reverse($teams);
180 197
 			$away = $reverse[$i];
181 198
 
182
-			if (($home == \TournamentGenerator\DUMMY_TEAM || $away == \TournamentGenerator\DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT
199
+			if (($home == \TournamentGenerator\DUMMY_TEAM || $away == \TournamentGenerator\DUMMY_TEAM)) {
200
+				continue;
201
+			}
202
+			// SKIP WHEN DUMMY_TEAM IS PRESENT
183 203
 
184 204
 			$bracket[] = new \TournamentGenerator\Game([$home, $away], $group);
185 205
 
Please login to merge, or discard this patch.
src/classes/class_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.