| @@ -16,7 +16,7 @@ discard block | ||
| 16 | 16 | |
| 17 | 17 | // CALCULATE BYES | 
| 18 | 18 | $byes = 0; | 
| 19 | -		if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { | |
| 19 | +		if (!\TournamentGenerator\isPowerOf2($countTeams)) { | |
| 20 | 20 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); | 
| 21 | 21 | $byes = $nextPow-$countTeams; | 
| 22 | 22 | } | 
| @@ -27,7 +27,7 @@ discard block | ||
| 27 | 27 | |
| 28 | 28 | $previousGroups = []; | 
| 29 | 29 | |
| 30 | -		for ($i=1; $i <= (($countTeams+$byes)/2); $i++) { | |
| 30 | +		for ($i = 1; $i <= (($countTeams+$byes)/2); $i++) { | |
| 31 | 31 | $g = $startRound->group([ | 
| 32 | 32 | 'name' => 'Round 1 - '.$i, | 
| 33 | 33 | 'inGame' => 2, | 
| @@ -38,10 +38,10 @@ discard block | ||
| 38 | 38 | |
| 39 | 39 | $this->splitTeams(); | 
| 40 | 40 | |
| 41 | -		for ($r=2; $r <= $roundsNum; $r++) { | |
| 41 | +		for ($r = 2; $r <= $roundsNum; $r++) { | |
| 42 | 42 | $groups = []; | 
| 43 | 43 |  			$round = $this->round('Round '.$r); | 
| 44 | -			for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { | |
| 44 | +			for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { | |
| 45 | 45 | $group = $round->group([ | 
| 46 | 46 | 'name' => 'Round '.$r.' - '.$g, | 
| 47 | 47 | 'inGame' => 2, | 
| @@ -50,7 +50,7 @@ | ||
| 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' => TWO_TWO | 
| @@ -12,7 +12,9 @@ | ||
| 12 | 12 | |
| 13 | 13 |  	public function generate() { | 
| 14 | 14 | |
| 15 | -		if (count($this->getTeams()) === 0) throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); | |
| 15 | +		if (count($this->getTeams()) === 0) { | |
| 16 | +			throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); | |
| 17 | + } | |
| 16 | 18 | |
| 17 | 19 | |
| 18 | 20 |  		$round1 = $this->round('Round 1'); | 
| @@ -19,7 +19,7 @@ discard block | ||
| 19 | 19 | // CALCULATE BYES | 
| 20 | 20 | $byes = 0; | 
| 21 | 21 | $nextPow = $countTeams; | 
| 22 | -		if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { | |
| 22 | +		if (!\TournamentGenerator\isPowerOf2($countTeams)) { | |
| 23 | 23 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); | 
| 24 | 24 | $byes = $nextPow-$countTeams; | 
| 25 | 25 | } | 
| @@ -38,7 +38,7 @@ discard block | ||
| 38 | 38 | $groupIds = []; | 
| 39 | 39 | $allGroups = []; | 
| 40 | 40 | |
| 41 | -		for ($i=1; $i <= $startGroups; $i++) { | |
| 41 | +		for ($i = 1; $i <= $startGroups; $i++) { | |
| 42 | 42 | $g = $startRound->group([ | 
| 43 | 43 | 'name' => 'Start group - '.$i, | 
| 44 | 44 | 'inGame' => 2, | 
| @@ -52,7 +52,7 @@ discard block | ||
| 52 | 52 | // SPLIT TEAMS EVENLY | 
| 53 | 53 | $this->splitTeams(); | 
| 54 | 54 | |
| 55 | -		for ($r=2; $r <= $roundsNum-1; $r++) { | |
| 55 | +		for ($r = 2; $r <= $roundsNum-1; $r++) { | |
| 56 | 56 | $groups = []; | 
| 57 | 57 | $losingGroups = []; | 
| 58 | 58 |  			$round = $this->round('Round '.$r); | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); | 
| 64 | 64 | $order = 2; | 
| 65 | 65 |  			if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES | 
| 66 | -				for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { | |
| 66 | +				for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { | |
| 67 | 67 | $group = $round->group([ | 
| 68 | 68 | 'name' => 'Round '.$r.' - loss '.$g, | 
| 69 | 69 | 'inGame' => 2, | 
| @@ -91,11 +91,11 @@ discard block | ||
| 91 | 91 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); | 
| 92 | 92 | $byesGroupsNums = []; | 
| 93 | 93 | $byesProgressed = 0; | 
| 94 | -				for ($i=0; $i < $losingByes; $i++) { | |
| 94 | +				for ($i = 0; $i < $losingByes; $i++) { | |
| 95 | 95 | $byesGroupsNums[] = $n-($i*2); | 
| 96 | 96 | } | 
| 97 | 97 | $lastGroup = 0; | 
| 98 | -				for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { | |
| 98 | +				for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { | |
| 99 | 99 | $group = $round->group([ | 
| 100 | 100 | 'name' => 'Round '.$r.' - loss '.$g, | 
| 101 | 101 | 'inGame' => 2, | 
| @@ -112,14 +112,14 @@ discard block | ||
| 112 | 112 | } | 
| 113 | 113 |  					else { | 
| 114 | 114 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE | 
| 115 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE | |
| 115 | + if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE | |
| 116 | 116 | $lastGroup += 2; | 
| 117 | 117 | } | 
| 118 | 118 | } | 
| 119 | 119 | } | 
| 120 | 120 | // WINNING SIDE LIKE SINGLE ELIMINATION | 
| 121 | 121 | $order = 1; | 
| 122 | -			for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { | |
| 122 | +			for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { | |
| 123 | 123 | $group = $round->group([ | 
| 124 | 124 | 'name' => 'Round '.$r.' - win '.$g, | 
| 125 | 125 | 'inGame' => 2, | 
| @@ -15,7 +15,9 @@ discard block | ||
| 15 | 15 | |
| 16 | 16 | $countTeams = count($this->getTeams()); | 
| 17 | 17 | |
| 18 | -		if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); | |
| 18 | +		if ($countTeams < 3) { | |
| 19 | +			throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); | |
| 20 | + } | |
| 19 | 21 | |
| 20 | 22 | |
| 21 | 23 | // CALCULATE BYES | 
| @@ -79,15 +81,19 @@ discard block | ||
| 79 | 81 |  					if ($r === 2) { // FIRST LOSING ROUND | 
| 80 | 82 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP | 
| 81 | 83 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP | 
| 82 | - } | |
| 83 | -					elseif ($losingGroupTeamsCount >= 2) { | |
| 84 | +					} elseif ($losingGroupTeamsCount >= 2) { | |
| 84 | 85 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE | 
| 85 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE | |
| 86 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE | |
| 86 | +						if (isset(array_reverse($previousGroups)[$g-1])) { | |
| 87 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); | |
| 88 | + } | |
| 89 | + // PROGREESS FROM WINNING GROUP BEFORE | |
| 90 | +						else { | |
| 91 | + $previousLosingGroups[$g]->progression($group, 0, 1); | |
| 92 | + } | |
| 93 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE | |
| 87 | 94 | } | 
| 88 | 95 | } | 
| 89 | - } | |
| 90 | -			else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES | |
| 96 | +			} else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES | |
| 91 | 97 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 | 
| 92 | 98 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); | 
| 93 | 99 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); | 
| @@ -111,10 +117,12 @@ discard block | ||
| 111 | 117 |  					if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE | 
| 112 | 118 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE | 
| 113 | 119 | $byesProgressed++; | 
| 114 | - } | |
| 115 | -					else { | |
| 120 | +					} else { | |
| 116 | 121 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE | 
| 117 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE | |
| 122 | +						if (isset($previousLosingGroups[$lastGroup + 1])) { | |
| 123 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); | |
| 124 | + } | |
| 125 | + // PROGREESS FROM LOSING GROUP BEFORE | |
| 118 | 126 | $lastGroup += 2; | 
| 119 | 127 | } | 
| 120 | 128 | } | 
| @@ -94,10 +94,10 @@ | ||
| 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); | 
| @@ -78,10 +78,10 @@ discard block | ||
| 78 | 78 |  		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)); | 
| 79 | 79 | return $this; | 
| 80 | 80 | } | 
| 81 | -	public function getTeams(){ | |
| 81 | +	public function getTeams() { | |
| 82 | 82 | return $this->teams; | 
| 83 | 83 | } | 
| 84 | -	public function getTeamsIds(){ | |
| 84 | +	public function getTeamsIds() { | |
| 85 | 85 | $ids = []; | 
| 86 | 86 |  		foreach ($this->teams as $team) { | 
| 87 | 87 | $ids[] = $team->id; | 
| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 | $team->addLoss($this->group->id); | 
| 129 | 129 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; | 
| 130 | 130 | } | 
| 131 | - break;} | |
| 131 | + break; } | |
| 132 | 132 |  				case 3:{ | 
| 133 | 133 |  					switch ($i) { | 
| 134 | 134 | case 1: | 
| @@ -147,7 +147,7 @@ discard block | ||
| 147 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; | 
| 148 | 148 | break; | 
| 149 | 149 | } | 
| 150 | - break;} | |
| 150 | + break; } | |
| 151 | 151 |  				case 4:{ | 
| 152 | 152 |  					switch ($i) { | 
| 153 | 153 | case 1: | 
| @@ -171,7 +171,7 @@ discard block | ||
| 171 | 171 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; | 
| 172 | 172 | break; | 
| 173 | 173 | } | 
| 174 | - break;} | |
| 174 | + break; } | |
| 175 | 175 | } | 
| 176 | 176 | $team->groupResults[$this->group->id]['score'] += $score; | 
| 177 | 177 | $i++; | 
| @@ -25,9 +25,10 @@ discard block | ||
| 25 | 25 |  			if (!$team instanceof Team) { | 
| 26 | 26 | $error[] = $team; | 
| 27 | 27 | unset($teams[$key]); | 
| 28 | - } | |
| 29 | -			else { | |
| 30 | - if (!isset($team->games[$group->id])) $team->games[$group->id] = []; | |
| 28 | +			} else { | |
| 29 | +				if (!isset($team->games[$group->id])) { | |
| 30 | + $team->games[$group->id] = []; | |
| 31 | + } | |
| 31 | 32 | $team->games[$group->id][] = $this; | 
| 32 | 33 | $tids[] = $team->id; | 
| 33 | 34 | } | 
| @@ -36,12 +37,16 @@ discard block | ||
| 36 | 37 |  		foreach ($this->teams as $team) { | 
| 37 | 38 |  			foreach ($tids as $id) { | 
| 38 | 39 |  				if ($team->id !== $id) { | 
| 39 | - if (!isset($team->gamesWith[$group->id][$id])) $team->gamesWith[$group->id][$id] = 0; | |
| 40 | +					if (!isset($team->gamesWith[$group->id][$id])) { | |
| 41 | + $team->gamesWith[$group->id][$id] = 0; | |
| 42 | + } | |
| 40 | 43 | $team->gamesWith[$group->id][$id]++; | 
| 41 | 44 | } | 
| 42 | 45 | } | 
| 43 | 46 | } | 
| 44 | -		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)); | |
| 47 | +		if (count($error) > 0) { | |
| 48 | +			throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); | |
| 49 | + } | |
| 45 | 50 | } | 
| 46 | 51 | |
| 47 | 52 |  	public function addTeam(...$teams) { | 
| @@ -49,9 +54,13 @@ discard block | ||
| 49 | 54 |  		foreach ($this->teams as $team) { | 
| 50 | 55 |  			foreach ($teams as $team2) { | 
| 51 | 56 |  				if ($team2 instanceof Team) { | 
| 52 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; | |
| 57 | +					if (!isset($team->gamesWith[$this->group->id][$team2->id])) { | |
| 58 | + $team->gamesWith[$this->group->id][$team2->id] = 0; | |
| 59 | + } | |
| 53 | 60 | $team->gamesWith[$this->group->id][$team2->id]++; | 
| 54 | - if (!isset($team2->gamesWith[$this->group->id][$team->id])) $team2->gamesWith[$this->group->id][$team->id] = 0; | |
| 61 | +					if (!isset($team2->gamesWith[$this->group->id][$team->id])) { | |
| 62 | + $team2->gamesWith[$this->group->id][$team->id] = 0; | |
| 63 | + } | |
| 55 | 64 | $team2->gamesWith[$this->group->id][$team->id]++; | 
| 56 | 65 | } | 
| 57 | 66 | } | 
| @@ -59,21 +68,26 @@ discard block | ||
| 59 | 68 |  		foreach ($teams as $key => $team) { | 
| 60 | 69 |  			if ($team instanceof Team) { | 
| 61 | 70 | $this->teams[] = $team; | 
| 62 | - if (!isset($team->games[$this->group->id])) $team->games[$this->group->id] = []; | |
| 71 | +				if (!isset($team->games[$this->group->id])) { | |
| 72 | + $team->games[$this->group->id] = []; | |
| 73 | + } | |
| 63 | 74 | $team->games[$this->group->id][] = $this; | 
| 64 | 75 |  				foreach ($teams as $key2 => $team2) { | 
| 65 | 76 |  					if ($team2 instanceof Team) { | 
| 66 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; | |
| 77 | +						if (!isset($team->gamesWith[$this->group->id][$team2->id])) { | |
| 78 | + $team->gamesWith[$this->group->id][$team2->id] = 0; | |
| 79 | + } | |
| 67 | 80 | $team->gamesWith[$this->group->id][$team2->id]++; | 
| 68 | 81 | } | 
| 69 | 82 | } | 
| 70 | - } | |
| 71 | -			else { | |
| 83 | +			} else { | |
| 72 | 84 | $error[] = $team; | 
| 73 | 85 | unset($teams[$key]); | 
| 74 | 86 | } | 
| 75 | 87 | } | 
| 76 | -		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)); | |
| 88 | +		if (count($error) > 0) { | |
| 89 | +			throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); | |
| 90 | + } | |
| 77 | 91 | return $this; | 
| 78 | 92 | } | 
| 79 | 93 |  	public function getTeams(){ | 
| @@ -88,7 +102,9 @@ discard block | ||
| 88 | 102 | } | 
| 89 | 103 |  	public function getTeam(string $id) { | 
| 90 | 104 |  		foreach ($this->teams as $team) { | 
| 91 | - if ($team->id === $id) return $team; | |
| 105 | +			if ($team->id === $id) { | |
| 106 | + return $team; | |
| 107 | + } | |
| 92 | 108 | } | 
| 93 | 109 | return false; | 
| 94 | 110 | } | 
| @@ -99,12 +115,16 @@ discard block | ||
| 99 | 115 | * ) | 
| 100 | 116 | */ | 
| 101 | 117 |  	public function setResults(array $results = []) { | 
| 102 | - if (count($this->results) === 0) $this->resetResults(); | |
| 118 | +		if (count($this->results) === 0) { | |
| 119 | + $this->resetResults(); | |
| 120 | + } | |
| 103 | 121 | arsort($results); | 
| 104 | 122 | $i = 1; | 
| 105 | 123 |  		foreach ($results as $id => $score) { | 
| 106 | 124 | $team = $this->getTeam($id); | 
| 107 | -			if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); | |
| 125 | +			if ($team === false) { | |
| 126 | +				throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); | |
| 127 | + } | |
| 108 | 128 | $this->results[$team->id] = ['score' => $score]; | 
| 109 | 129 | $team->sumScore += $score; | 
| 110 | 130 | $prev = prev($results); | 
| @@ -116,13 +136,11 @@ discard block | ||
| 116 | 136 | $this->drawIds[] = $team->id; | 
| 117 | 137 | $team->addDraw($this->group->id); | 
| 118 | 138 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; | 
| 119 | - } | |
| 120 | -					elseif ($i === 1) { | |
| 139 | +					} elseif ($i === 1) { | |
| 121 | 140 | $this->winId = $team->id; | 
| 122 | 141 | $team->addWin($this->group->id); | 
| 123 | 142 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; | 
| 124 | - } | |
| 125 | -					else { | |
| 143 | +					} else { | |
| 126 | 144 | $this->lossId = $team->id; | 
| 127 | 145 | $team->addLoss($this->group->id); | 
| 128 | 146 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; | 
| @@ -220,7 +238,9 @@ discard block | ||
| 220 | 238 | } | 
| 221 | 239 | |
| 222 | 240 |  	public function isPlayed() { | 
| 223 | - if (count($this->results) > 0) return true; | |
| 241 | +		if (count($this->results) > 0) { | |
| 242 | + return true; | |
| 243 | + } | |
| 224 | 244 | return false; | 
| 225 | 245 | } | 
| 226 | 246 | } | 
| @@ -22,11 +22,11 @@ discard block | ||
| 22 | 22 |  function circle_genGames2(array $teams = [], Group $group = null) { | 
| 23 | 23 | $bracket = []; // ARRAY OF GAMES | 
| 24 | 24 | |
| 25 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY | |
| 25 | + if (count($teams)%2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY | |
| 26 | 26 | |
| 27 | 27 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS | 
| 28 | 28 | |
| 29 | -	for ($i=0; $i < count($teams)-1; $i++) { | |
| 29 | +	for ($i = 0; $i < count($teams)-1; $i++) { | |
| 30 | 30 | $bracket = array_merge($bracket, circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND | 
| 31 | 31 | |
| 32 | 32 | $teams = circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET | 
| @@ -41,7 +41,7 @@ discard block | ||
| 41 | 41 | |
| 42 | 42 | $bracket = []; | 
| 43 | 43 | |
| 44 | -	for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS | |
| 44 | +	for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS | |
| 45 | 45 | |
| 46 | 46 | $home = $teams[$i]; | 
| 47 | 47 | $reverse = array_reverse($teams); | 
| @@ -22,7 +22,10 @@ discard block | ||
| 22 | 22 |  function circle_genGames2(array $teams = [], Group $group = null) { | 
| 23 | 23 | $bracket = []; // ARRAY OF GAMES | 
| 24 | 24 | |
| 25 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY | |
| 25 | +	if (count($teams) % 2 != 0) { | |
| 26 | + $teams[] = DUMMY_TEAM; | |
| 27 | + } | |
| 28 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY | |
| 26 | 29 | |
| 27 | 30 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS | 
| 28 | 31 | |
| @@ -47,7 +50,10 @@ discard block | ||
| 47 | 50 | $reverse = array_reverse($teams); | 
| 48 | 51 | $away = $reverse[$i]; | 
| 49 | 52 | |
| 50 | - if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT | |
| 53 | +		if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) { | |
| 54 | + continue; | |
| 55 | + } | |
| 56 | + // SKIP WHEN DUMMY_TEAM IS PRESENT | |
| 51 | 57 | |
| 52 | 58 | $bracket[] = new Game([$home, $away], $group); | 
| 53 | 59 | |
| @@ -68,11 +68,11 @@ discard block | ||
| 68 | 68 | return 'Group '.$this->name; | 
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | -	public function allowSkip(){ | |
| 71 | +	public function allowSkip() { | |
| 72 | 72 | $this->allowSkip = true; | 
| 73 | 73 | return $this; | 
| 74 | 74 | } | 
| 75 | -	public function disallowSkip(){ | |
| 75 | +	public function disallowSkip() { | |
| 76 | 76 | $this->allowSkip = false; | 
| 77 | 77 | return $this; | 
| 78 | 78 | } | 
| @@ -86,7 +86,7 @@ discard block | ||
| 86 | 86 | |
| 87 | 87 |  	public function addTeam(...$teams) { | 
| 88 | 88 |  		foreach ($teams as $team) { | 
| 89 | -			if ($team instanceof Team)  { | |
| 89 | +			if ($team instanceof Team) { | |
| 90 | 90 | $this->teams[] = $team; | 
| 91 | 91 | $team->groupResults[$this->id] = [ | 
| 92 | 92 | 'group' => $this, | 
| @@ -243,13 +243,13 @@ discard block | ||
| 243 | 243 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); | 
| 244 | 244 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); | 
| 245 | 245 | }); | 
| 246 | - break;} | |
| 246 | + break; } | |
| 247 | 247 |  			case SCORE:{ | 
| 248 | 248 |  				usort($this->teams, function($a, $b) { | 
| 249 | 249 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; | 
| 250 | 250 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); | 
| 251 | 251 | }); | 
| 252 | - break;} | |
| 252 | + break; } | |
| 253 | 253 | } | 
| 254 | 254 | return $this->getTeams($filters); | 
| 255 | 255 | } | 
| @@ -314,19 +314,19 @@ discard block | ||
| 314 | 314 |  		switch ($this->type) { | 
| 315 | 315 |  			case R_R:{ | 
| 316 | 316 | $this->games = $this->r_rGames(); | 
| 317 | - break;} | |
| 317 | + break; } | |
| 318 | 318 | case TWO_TWO: | 
| 319 | 319 | $teams = $this->teams; | 
| 320 | 320 | $discard = []; | 
| 321 | 321 | shuffle($teams); | 
| 322 | 322 | $count = count($teams); | 
| 323 | -				while (count($teams) % $this->inGame !== 0) { | |
| 323 | +				while (count($teams)%$this->inGame !== 0) { | |
| 324 | 324 | $discard[] = array_shift($teams); | 
| 325 | 325 | } | 
| 326 | 326 | |
| 327 | 327 |  				while (count($teams) > 0) { | 
| 328 | 328 | $tInGame = []; | 
| 329 | -					for ($i=0; $i < $this->inGame; $i++) { | |
| 329 | +					for ($i = 0; $i < $this->inGame; $i++) { | |
| 330 | 330 | $tInGame[] = array_shift($teams); | 
| 331 | 331 | } | 
| 332 | 332 | $this->game($tInGame); | 
| @@ -365,7 +365,7 @@ discard block | ||
| 365 | 365 | $this->games[] = $g; | 
| 366 | 366 | return $g; | 
| 367 | 367 | } | 
| 368 | -	public function addGame(Game ...$games){ | |
| 368 | +	public function addGame(Game ...$games) { | |
| 369 | 369 |  		foreach ($games as $game) { | 
| 370 | 370 | if ($game instanceof Game) $this->games[] = $game; | 
| 371 | 371 |  			else throw new \Exception('Trying to add game which is not instance of Game object.'); | 
| @@ -461,7 +461,7 @@ discard block | ||
| 461 | 461 |  			foreach ($games as $key => $game) { | 
| 462 | 462 | $gTeams = $game->getTeamsIds(); | 
| 463 | 463 | $suitable = true; | 
| 464 | -				$requiredTeams = array_filter($teams, function($a){ | |
| 464 | +				$requiredTeams = array_filter($teams, function($a) { | |
| 465 | 465 | return $a < 4; | 
| 466 | 466 | }); | 
| 467 | 467 |  				foreach ($gTeams as $tid) { | 
| @@ -512,7 +512,7 @@ discard block | ||
| 512 | 512 |  			foreach ($games as $key => $game) { | 
| 513 | 513 | $gTeams = $game->getTeamsIds(); | 
| 514 | 514 | $suitable = false; | 
| 515 | -				$requiredTeams = array_filter($teams, function($a){ | |
| 515 | +				$requiredTeams = array_filter($teams, function($a) { | |
| 516 | 516 | return $a < 4; | 
| 517 | 517 | }); | 
| 518 | 518 |  				foreach ($gTeams as $tid) { | 
| @@ -557,7 +557,7 @@ discard block | ||
| 557 | 557 | $games = array_merge($games, $games); | 
| 558 | 558 | } | 
| 559 | 559 | // $this->orderGames(); | 
| 560 | - break;} | |
| 560 | + break; } | |
| 561 | 561 |  			case 4:{ | 
| 562 | 562 | $teamsB = $teams; | 
| 563 | 563 | $lockedTeam1 = array_shift($teamsB); | 
| @@ -575,7 +575,7 @@ discard block | ||
| 575 | 575 | } | 
| 576 | 576 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); | 
| 577 | 577 | // $this->orderGames(); | 
| 578 | - break;} | |
| 578 | + break; } | |
| 579 | 579 | } | 
| 580 | 580 | return $games; | 
| 581 | 581 | } | 
| @@ -601,7 +601,7 @@ discard block | ||
| 601 | 601 | } | 
| 602 | 602 | return $this; | 
| 603 | 603 | } | 
| 604 | -	public function isPlayed(){ | |
| 604 | +	public function isPlayed() { | |
| 605 | 605 |  		foreach ($this->games as $game) { | 
| 606 | 606 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; | 
| 607 | 607 | } | 
| @@ -33,27 +33,40 @@ discard block | ||
| 33 | 33 |  		foreach ($settings as $key => $value) { | 
| 34 | 34 |  			switch ($key) { | 
| 35 | 35 | case 'name': | 
| 36 | -					if (gettype($value) !== 'string') throw new \Exception('Expected string as group name '.gettype($value).' given'); | |
| 36 | +					if (gettype($value) !== 'string') { | |
| 37 | +						throw new \Exception('Expected string as group name '.gettype($value).' given'); | |
| 38 | + } | |
| 37 | 39 | $this->name = $value; | 
| 38 | 40 | break; | 
| 39 | 41 | case 'type': | 
| 40 | -					if (!in_array($value, groupTypes)) throw new \Exception('Unknown group type: '.$value); | |
| 42 | +					if (!in_array($value, groupTypes)) { | |
| 43 | +						throw new \Exception('Unknown group type: '.$value); | |
| 44 | + } | |
| 41 | 45 | $this->type = $value; | 
| 42 | 46 | break; | 
| 43 | 47 | case 'ordering': | 
| 44 | -					if (!in_array($value, orderingTypes)) throw new \Exception('Unknown group ordering: '.$value); | |
| 48 | +					if (!in_array($value, orderingTypes)) { | |
| 49 | +						throw new \Exception('Unknown group ordering: '.$value); | |
| 50 | + } | |
| 45 | 51 | $this->ordering = $value; | 
| 46 | 52 | break; | 
| 47 | 53 | case 'inGame': | 
| 48 | -					if (gettype($value) !== 'integer') throw new \Exception('Expected integer as inGame '.gettype($value).' given'); | |
| 49 | -					else if ($value < 2 || $value > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); | |
| 54 | +					if (gettype($value) !== 'integer') { | |
| 55 | +						throw new \Exception('Expected integer as inGame '.gettype($value).' given'); | |
| 56 | +					} else if ($value < 2 || $value > 4) { | |
| 57 | +						throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); | |
| 58 | + } | |
| 50 | 59 | $this->inGame = $value; | 
| 51 | 60 | break; | 
| 52 | 61 | case 'maxSize': | 
| 53 | - if (gettype($value) === 'integer') $this->maxSize = $value; | |
| 62 | +					if (gettype($value) === 'integer') { | |
| 63 | + $this->maxSize = $value; | |
| 64 | + } | |
| 54 | 65 | break; | 
| 55 | 66 | case 'order': | 
| 56 | - if (gettype($value) === 'integer') $this->order = $value; | |
| 67 | +					if (gettype($value) === 'integer') { | |
| 68 | + $this->order = $value; | |
| 69 | + } | |
| 57 | 70 | break; | 
| 58 | 71 | } | 
| 59 | 72 | } | 
| @@ -92,10 +105,11 @@ discard block | ||
| 92 | 105 | 'second' => 0, | 
| 93 | 106 | 'third' => 0 | 
| 94 | 107 | ]; | 
| 95 | - } | |
| 96 | -			elseif (gettype($team) === 'array') { | |
| 108 | +			} elseif (gettype($team) === 'array') { | |
| 97 | 109 |  				foreach ($team as $team2) { | 
| 98 | - if ($team2 instanceof Team) $this->teams[] = $team2; | |
| 110 | +					if ($team2 instanceof Team) { | |
| 111 | + $this->teams[] = $team2; | |
| 112 | + } | |
| 99 | 113 | $team2->groupResults[$this->id] = [ | 
| 100 | 114 | 'group' => $this, | 
| 101 | 115 | 'points' => 0, | 
| @@ -107,16 +121,20 @@ discard block | ||
| 107 | 121 | 'third' => 0 | 
| 108 | 122 | ]; | 
| 109 | 123 | } | 
| 124 | +			} else { | |
| 125 | +				throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 110 | 126 | } | 
| 111 | -			else throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 112 | 127 | } | 
| 113 | 128 | return $this; | 
| 114 | 129 | } | 
| 115 | 130 |  	public function getTeams($filters = []) { | 
| 116 | 131 | $teams = $this->teams; | 
| 117 | 132 | |
| 118 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; | |
| 119 | - elseif (gettype($filters) !== 'array') $filters = []; | |
| 133 | +		if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { | |
| 134 | + $filters = [$filters]; | |
| 135 | +		} elseif (gettype($filters) !== 'array') { | |
| 136 | + $filters = []; | |
| 137 | + } | |
| 120 | 138 | |
| 121 | 139 | // APPLY FILTERS | 
| 122 | 140 |  		foreach ($filters as $key => $filter) { | 
| @@ -124,27 +142,31 @@ discard block | ||
| 124 | 142 |  				switch (strtolower($key)) { | 
| 125 | 143 | case 'and': | 
| 126 | 144 |  						foreach ($teams as $tkey => $team) { | 
| 127 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY | |
| 145 | +							if (!$this->filterAnd($team, $filter)) { | |
| 146 | + unset($teams[$tkey]); | |
| 147 | + } | |
| 148 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY | |
| 128 | 149 | } | 
| 129 | 150 | break; | 
| 130 | 151 | case 'or': | 
| 131 | 152 |  						foreach ($teams as $tkey => $team) { | 
| 132 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY | |
| 153 | +							if (!$this->filterOr($team, $filter)) { | |
| 154 | + unset($teams[$tkey]); | |
| 155 | + } | |
| 156 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY | |
| 133 | 157 | } | 
| 134 | 158 | break; | 
| 135 | 159 | default: | 
| 136 | 160 |  						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); | 
| 137 | 161 | break; | 
| 138 | 162 | } | 
| 139 | - } | |
| 140 | -			elseif ($filter instanceof TeamFilter) { | |
| 163 | +			} elseif ($filter instanceof TeamFilter) { | |
| 141 | 164 |  				foreach ($teams as $tkey => $team) { | 
| 142 | 165 |  					if (!$filter->validate($team, $this->id, 'sum', $this)) { | 
| 143 | 166 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY | 
| 144 | 167 | } | 
| 145 | 168 | } | 
| 146 | - } | |
| 147 | -			else { | |
| 169 | +			} else { | |
| 148 | 170 |  				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); | 
| 149 | 171 | } | 
| 150 | 172 | } | 
| @@ -155,20 +177,24 @@ discard block | ||
| 155 | 177 |  			if (gettype($value) === 'array') { | 
| 156 | 178 |  				switch (strtolower($key)) { | 
| 157 | 179 | case 'and': | 
| 158 | - if ($this->filterAnd($team, $value)) return false; | |
| 180 | +						if ($this->filterAnd($team, $value)) { | |
| 181 | + return false; | |
| 182 | + } | |
| 159 | 183 | break; | 
| 160 | 184 | case 'or': | 
| 161 | - if ($this->filterOr($team, $value)) return false; | |
| 185 | +						if ($this->filterOr($team, $value)) { | |
| 186 | + return false; | |
| 187 | + } | |
| 162 | 188 | break; | 
| 163 | 189 | default: | 
| 164 | 190 |  						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); | 
| 165 | 191 | break; | 
| 166 | 192 | } | 
| 167 | - } | |
| 168 | -			elseif ($value instanceof TeamFilter) { | |
| 169 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; | |
| 170 | - } | |
| 171 | -			else { | |
| 193 | +			} elseif ($value instanceof TeamFilter) { | |
| 194 | +				if (!$value->validate($team, $this->id, 'sum', $this)) { | |
| 195 | + return false; | |
| 196 | + } | |
| 197 | +			} else { | |
| 172 | 198 |  				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); | 
| 173 | 199 | } | 
| 174 | 200 | } | 
| @@ -179,20 +205,24 @@ discard block | ||
| 179 | 205 |  			if (gettype($value) === 'array') { | 
| 180 | 206 |  				switch (strtolower($key)) { | 
| 181 | 207 | case 'and': | 
| 182 | - if ($this->filterAnd($team, $value)) return true; | |
| 208 | +						if ($this->filterAnd($team, $value)) { | |
| 209 | + return true; | |
| 210 | + } | |
| 183 | 211 | break; | 
| 184 | 212 | case 'or': | 
| 185 | - if ($this->filterOr($team, $value)) return true; | |
| 213 | +						if ($this->filterOr($team, $value)) { | |
| 214 | + return true; | |
| 215 | + } | |
| 186 | 216 | break; | 
| 187 | 217 | default: | 
| 188 | 218 |  						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); | 
| 189 | 219 | break; | 
| 190 | 220 | } | 
| 191 | - } | |
| 192 | -			elseif ($value instanceof TeamFilter) { | |
| 193 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; | |
| 194 | - } | |
| 195 | -			else { | |
| 221 | +			} elseif ($value instanceof TeamFilter) { | |
| 222 | +				if (!$value->validate($team, $this->id, 'sum', $this)) { | |
| 223 | + return true; | |
| 224 | + } | |
| 225 | +			} else { | |
| 196 | 226 |  				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); | 
| 197 | 227 | } | 
| 198 | 228 | } | 
| @@ -214,16 +244,22 @@ discard block | ||
| 214 | 244 | return $t; | 
| 215 | 245 | } | 
| 216 | 246 |  	public function setType(string $type = R_R) { | 
| 217 | - if (in_array($type, groupTypes)) $this->type = $type; | |
| 218 | -		else throw new \Exception('Unknown group type: '.$type); | |
| 247 | +		if (in_array($type, groupTypes)) { | |
| 248 | + $this->type = $type; | |
| 249 | +		} else { | |
| 250 | +			throw new \Exception('Unknown group type: '.$type); | |
| 251 | + } | |
| 219 | 252 | return $this; | 
| 220 | 253 | } | 
| 221 | 254 |  	public function getType() { | 
| 222 | 255 | return $this->type; | 
| 223 | 256 | } | 
| 224 | 257 |  	public function setOrdering(string $ordering = POINTS) { | 
| 225 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; | |
| 226 | -		else throw new \Exception('Unknown group ordering: '.$ordering); | |
| 258 | +		if (in_array($ordering, orderingTypes)) { | |
| 259 | + $this->ordering = $ordering; | |
| 260 | +		} else { | |
| 261 | +			throw new \Exception('Unknown group ordering: '.$ordering); | |
| 262 | + } | |
| 227 | 263 | return $this; | 
| 228 | 264 | } | 
| 229 | 265 |  	public function getOrdering() { | 
| @@ -233,14 +269,20 @@ discard block | ||
| 233 | 269 |  		switch ($this->ordering) { | 
| 234 | 270 |  			case POINTS:{ | 
| 235 | 271 |  				usort($this->teams, function($a, $b) { | 
| 236 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; | |
| 237 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); | |
| 272 | +					if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { | |
| 273 | + return 0; | |
| 274 | + } | |
| 275 | +					if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { | |
| 276 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); | |
| 277 | + } | |
| 238 | 278 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); | 
| 239 | 279 | }); | 
| 240 | 280 | break;} | 
| 241 | 281 |  			case SCORE:{ | 
| 242 | 282 |  				usort($this->teams, function($a, $b) { | 
| 243 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; | |
| 283 | +					if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { | |
| 284 | + return 0; | |
| 285 | + } | |
| 244 | 286 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); | 
| 245 | 287 | }); | 
| 246 | 288 | break;} | 
| @@ -249,10 +291,14 @@ discard block | ||
| 249 | 291 | } | 
| 250 | 292 |  	public function setInGame(int $inGame) { | 
| 251 | 293 |  		if (gettype($inGame) === 'integer') { | 
| 252 | - if ($inGame === 2 || $inGame === 3 || $inGame === 4) $this->inGame = $inGame; | |
| 253 | -			else throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); | |
| 294 | +			if ($inGame === 2 || $inGame === 3 || $inGame === 4) { | |
| 295 | + $this->inGame = $inGame; | |
| 296 | +			} else { | |
| 297 | +				throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); | |
| 298 | + } | |
| 299 | +		} else { | |
| 300 | +			throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); | |
| 254 | 301 | } | 
| 255 | -		else throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); | |
| 256 | 302 | } | 
| 257 | 303 |  	public function getInGame() { | 
| 258 | 304 | return $this->inGame; | 
| @@ -280,16 +326,13 @@ discard block | ||
| 280 | 326 |  		foreach ($teams as $team) { | 
| 281 | 327 |  			if ($team instanceOf Team) { | 
| 282 | 328 | $this->progressed[] = $team->id; | 
| 283 | - } | |
| 284 | -			elseif (gettype($team) === 'string' || gettype($team) === 'integer') { | |
| 329 | +			} elseif (gettype($team) === 'string' || gettype($team) === 'integer') { | |
| 285 | 330 | $this->progressed[] = $team; | 
| 286 | - } | |
| 287 | -			elseif (gettype($team) === 'array') { | |
| 331 | +			} elseif (gettype($team) === 'array') { | |
| 288 | 332 |  				foreach ($team as $teamInner) { | 
| 289 | 333 |  					if ($teamInner instanceOf Team) { | 
| 290 | 334 | $this->progressed[] = $teamInner->id; | 
| 291 | - } | |
| 292 | -					elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { | |
| 335 | +					} elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { | |
| 293 | 336 | $this->progressed[] = $teamInner; | 
| 294 | 337 | } | 
| 295 | 338 | } | 
| @@ -325,7 +368,9 @@ discard block | ||
| 325 | 368 | $this->game($tInGame); | 
| 326 | 369 | } | 
| 327 | 370 | |
| 328 | -				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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); | |
| 371 | +				if (count($discard) > 0 && !$this->allowSkip) { | |
| 372 | +					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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); | |
| 373 | + } | |
| 329 | 374 | break; | 
| 330 | 375 | case COND_SPLIT: | 
| 331 | 376 | $games = []; | 
| @@ -341,12 +386,15 @@ discard block | ||
| 341 | 386 |  					while ($g > 0) { | 
| 342 | 387 |  						foreach ($games as $key => $group) { | 
| 343 | 388 | $this->games[] = array_shift($games[$key]); | 
| 344 | - if (count($games[$key]) === 0) unset($games[$key]); | |
| 389 | +							if (count($games[$key]) === 0) { | |
| 390 | + unset($games[$key]); | |
| 391 | + } | |
| 345 | 392 | $g--; | 
| 346 | 393 | } | 
| 347 | 394 | } | 
| 395 | +				} else { | |
| 396 | + $this->games = $this->r_rGames(); | |
| 348 | 397 | } | 
| 349 | - else $this->games = $this->r_rGames(); | |
| 350 | 398 | break; | 
| 351 | 399 | } | 
| 352 | 400 | return $this->games; | 
| @@ -358,8 +406,11 @@ discard block | ||
| 358 | 406 | } | 
| 359 | 407 |  	public function addGame(Game ...$games){ | 
| 360 | 408 |  		foreach ($games as $game) { | 
| 361 | - if ($game instanceof Game) $this->games[] = $game; | |
| 362 | -			else throw new \Exception('Trying to add game which is not instance of Game object.'); | |
| 409 | +			if ($game instanceof Game) { | |
| 410 | + $this->games[] = $game; | |
| 411 | +			} else { | |
| 412 | +				throw new \Exception('Trying to add game which is not instance of Game object.'); | |
| 413 | + } | |
| 363 | 414 | } | 
| 364 | 415 | return $this; | 
| 365 | 416 | } | 
| @@ -387,21 +438,30 @@ discard block | ||
| 387 | 438 | $teams[$team->id] = 0; | 
| 388 | 439 | } | 
| 389 | 440 |  			foreach (end($this->games)->getTeams() as $team) { | 
| 390 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; | |
| 391 | - else $teams[$team->id] += 4; | |
| 441 | +				if (!isset($teams[$team->id])) { | |
| 442 | + $teams[$team->id] = 4; | |
| 443 | +				} else { | |
| 444 | + $teams[$team->id] += 4; | |
| 445 | + } | |
| 392 | 446 | } | 
| 393 | 447 | $g = prev($this->games); | 
| 394 | 448 |  			if ($g instanceof Game) { | 
| 395 | 449 |  				foreach ($g->getTeams() as $team) { | 
| 396 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; | |
| 397 | - else $teams[$team->id] += 2; | |
| 450 | +					if (!isset($teams[$team->id])) { | |
| 451 | + $teams[$team->id] = 2; | |
| 452 | +					} else { | |
| 453 | + $teams[$team->id] += 2; | |
| 454 | + } | |
| 398 | 455 | } | 
| 399 | 456 | } | 
| 400 | 457 | $g = prev($this->games); | 
| 401 | 458 |  			if ($g instanceof Game) { | 
| 402 | 459 |  				foreach ($g->getTeams() as $team) { | 
| 403 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; | |
| 404 | - else $teams[$team->id]++; | |
| 460 | +					if (!isset($teams[$team->id])) { | |
| 461 | + $teams[$team->id] = 1; | |
| 462 | +					} else { | |
| 463 | + $teams[$team->id]++; | |
| 464 | + } | |
| 405 | 465 | } | 
| 406 | 466 | } | 
| 407 | 467 | |
| @@ -423,7 +483,9 @@ discard block | ||
| 423 | 483 | break; | 
| 424 | 484 | } | 
| 425 | 485 | } | 
| 426 | - if ($found) continue; | |
| 486 | +			if ($found) { | |
| 487 | + continue; | |
| 488 | + } | |
| 427 | 489 | |
| 428 | 490 | // CYCLE 2 | 
| 429 | 491 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) | 
| @@ -444,7 +506,9 @@ discard block | ||
| 444 | 506 | break; | 
| 445 | 507 | } | 
| 446 | 508 | } | 
| 447 | - if ($found) continue; | |
| 509 | +			if ($found) { | |
| 510 | + continue; | |
| 511 | + } | |
| 448 | 512 | |
| 449 | 513 | // CYCLE 3 | 
| 450 | 514 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) | 
| @@ -475,7 +539,9 @@ discard block | ||
| 475 | 539 | break; | 
| 476 | 540 | } | 
| 477 | 541 | } | 
| 478 | - if ($found) continue; | |
| 542 | +			if ($found) { | |
| 543 | + continue; | |
| 544 | + } | |
| 479 | 545 | |
| 480 | 546 | // CYCLE 4 | 
| 481 | 547 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) | 
| @@ -496,7 +562,9 @@ discard block | ||
| 496 | 562 | break; | 
| 497 | 563 | } | 
| 498 | 564 | } | 
| 499 | - if ($found) continue; | |
| 565 | +			if ($found) { | |
| 566 | + continue; | |
| 567 | + } | |
| 500 | 568 | |
| 501 | 569 | // CYCLE 5 | 
| 502 | 570 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) | 
| @@ -521,7 +589,9 @@ discard block | ||
| 521 | 589 | break; | 
| 522 | 590 | } | 
| 523 | 591 | } | 
| 524 | - if ($found) continue; | |
| 592 | +			if ($found) { | |
| 593 | + continue; | |
| 594 | + } | |
| 525 | 595 | |
| 526 | 596 | // CYCLE 6 | 
| 527 | 597 | // FIRST AVAILABLE GAME | 
| @@ -532,7 +602,9 @@ discard block | ||
| 532 | 602 | } | 
| 533 | 603 |  	public function r_rGames(array $teams = []) { | 
| 534 | 604 | $games = []; | 
| 535 | - if (count($teams) === 0) $teams = $this->teams; | |
| 605 | +		if (count($teams) === 0) { | |
| 606 | + $teams = $this->teams; | |
| 607 | + } | |
| 536 | 608 |  		switch ($this->inGame) { | 
| 537 | 609 | case 2: | 
| 538 | 610 | $games = circle_genGames2($teams, $this); | 
| @@ -580,7 +652,9 @@ discard block | ||
| 580 | 652 | $game->setResults($results); | 
| 581 | 653 | } | 
| 582 | 654 | $return = $this->sortTeams($filters); | 
| 583 | - if (!$reset) return $return; | |
| 655 | +		if (!$reset) { | |
| 656 | + return $return; | |
| 657 | + } | |
| 584 | 658 |  		foreach ($this->getGames() as $game) { | 
| 585 | 659 | $game->resetResults(); | 
| 586 | 660 | } | 
| @@ -588,13 +662,17 @@ discard block | ||
| 588 | 662 | } | 
| 589 | 663 |  	public function resetGames() { | 
| 590 | 664 |  		foreach ($this->getGames() as $game) { | 
| 591 | - if (isset($game)) $game->resetResults(); | |
| 665 | +			if (isset($game)) { | |
| 666 | + $game->resetResults(); | |
| 667 | + } | |
| 592 | 668 | } | 
| 593 | 669 | return $this; | 
| 594 | 670 | } | 
| 595 | 671 |  	public function isPlayed(){ | 
| 596 | 672 |  		foreach ($this->games as $game) { | 
| 597 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; | |
| 673 | +			if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { | |
| 674 | + return false; | |
| 675 | + } | |
| 598 | 676 | } | 
| 599 | 677 | return true; | 
| 600 | 678 | } | 
| @@ -25,7 +25,7 @@ discard block | ||
| 25 | 25 | return $this->name; | 
| 26 | 26 | } | 
| 27 | 27 | |
| 28 | -	public function addGroup(Group ...$groups){ | |
| 28 | +	public function addGroup(Group ...$groups) { | |
| 29 | 29 |  		foreach ($groups as $group) { | 
| 30 | 30 | if ($group instanceof Group) $this->groups[] = $group; | 
| 31 | 31 |  			else throw new \Exception('Trying to add group which is not an instance of Group class.'); | 
| @@ -37,21 +37,21 @@ discard block | ||
| 37 | 37 | $this->groups[] = $g->setSkip($this->allowSkip); | 
| 38 | 38 | return $g; | 
| 39 | 39 | } | 
| 40 | -	public function getGroups(){ | |
| 40 | +	public function getGroups() { | |
| 41 | 41 | $this->orderGroups(); | 
| 42 | 42 | return $this->groups; | 
| 43 | 43 | } | 
| 44 | 44 |  	public function orderGroups() { | 
| 45 | -		usort($this->groups, function($a, $b){ | |
| 46 | - return $a->order - $b->order; | |
| 45 | +		usort($this->groups, function($a, $b) { | |
| 46 | + return $a->order-$b->order; | |
| 47 | 47 | }); | 
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | -	public function allowSkip(){ | |
| 50 | +	public function allowSkip() { | |
| 51 | 51 | $this->allowSkip = true; | 
| 52 | 52 | return $this; | 
| 53 | 53 | } | 
| 54 | -	public function disallowSkip(){ | |
| 54 | +	public function disallowSkip() { | |
| 55 | 55 | $this->allowSkip = false; | 
| 56 | 56 | return $this; | 
| 57 | 57 | } | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | return $this->allowSkip; | 
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | -	public function genGames(){ | |
| 66 | +	public function genGames() { | |
| 67 | 67 | $games = []; | 
| 68 | 68 | $g = 0; | 
| 69 | 69 |  		foreach ($this->groups as $group) { | 
| @@ -87,7 +87,7 @@ discard block | ||
| 87 | 87 |  	public function getGames() { | 
| 88 | 88 | return $this->games; | 
| 89 | 89 | } | 
| 90 | -	public function isPlayed(){ | |
| 90 | +	public function isPlayed() { | |
| 91 | 91 |  		foreach ($this->groups as $group) { | 
| 92 | 92 | if (!$group->isPlayed()) return false; | 
| 93 | 93 | } | 
| @@ -96,7 +96,7 @@ discard block | ||
| 96 | 96 | |
| 97 | 97 |  	public function addTeam(...$teams) { | 
| 98 | 98 |  		foreach ($teams as $team) { | 
| 99 | -			if ($team instanceof Team)  { | |
| 99 | +			if ($team instanceof Team) { | |
| 100 | 100 | $this->teams[] = $team; | 
| 101 | 101 | } | 
| 102 | 102 |  			elseif (gettype($team) === 'array') { | 
| @@ -157,14 +157,14 @@ discard block | ||
| 157 | 157 | return $this; | 
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | -	public function progress(){ | |
| 160 | +	public function progress() { | |
| 161 | 161 |  		foreach ($this->groups as $group) { | 
| 162 | 162 | $group->progress(); | 
| 163 | 163 | } | 
| 164 | 164 | return $this; | 
| 165 | 165 | } | 
| 166 | 166 | |
| 167 | -	public function progressBlank(){ | |
| 167 | +	public function progressBlank() { | |
| 168 | 168 | if (!$this->isPlayed()) $this->simulate(); | 
| 169 | 169 |  		foreach ($this->groups as $group) { | 
| 170 | 170 | $group->progressBlank(); | 
| @@ -27,8 +27,11 @@ discard block | ||
| 27 | 27 | |
| 28 | 28 |  	public function addGroup(Group ...$groups){ | 
| 29 | 29 |  		foreach ($groups as $group) { | 
| 30 | - if ($group instanceof Group) $this->groups[] = $group; | |
| 31 | -			else throw new \Exception('Trying to add group which is not an instance of Group class.'); | |
| 30 | +			if ($group instanceof Group) { | |
| 31 | + $this->groups[] = $group; | |
| 32 | +			} else { | |
| 33 | +				throw new \Exception('Trying to add group which is not an instance of Group class.'); | |
| 34 | + } | |
| 32 | 35 | } | 
| 33 | 36 | return $this; | 
| 34 | 37 | } | 
| @@ -78,7 +81,9 @@ discard block | ||
| 78 | 81 |  		while ($g > 0) { | 
| 79 | 82 |  			foreach ($games as $key => $group) { | 
| 80 | 83 | $this->games[] = array_shift($games[$key]); | 
| 81 | - if (count($games[$key]) === 0) unset($games[$key]); | |
| 84 | +				if (count($games[$key]) === 0) { | |
| 85 | + unset($games[$key]); | |
| 86 | + } | |
| 82 | 87 | $g--; | 
| 83 | 88 | } | 
| 84 | 89 | } | 
| @@ -89,7 +94,9 @@ discard block | ||
| 89 | 94 | } | 
| 90 | 95 |  	public function isPlayed(){ | 
| 91 | 96 |  		foreach ($this->groups as $group) { | 
| 92 | - if (!$group->isPlayed()) return false; | |
| 97 | +			if (!$group->isPlayed()) { | |
| 98 | + return false; | |
| 99 | + } | |
| 93 | 100 | } | 
| 94 | 101 | return true; | 
| 95 | 102 | } | 
| @@ -98,10 +105,11 @@ discard block | ||
| 98 | 105 |  		foreach ($teams as $team) { | 
| 99 | 106 |  			if ($team instanceof Team)  { | 
| 100 | 107 | $this->teams[] = $team; | 
| 101 | - } | |
| 102 | -			elseif (gettype($team) === 'array') { | |
| 108 | +			} elseif (gettype($team) === 'array') { | |
| 103 | 109 |  				foreach ($team as $team2) { | 
| 104 | - if ($team2 instanceof Team) $this->teams[] = $team2; | |
| 110 | +					if ($team2 instanceof Team) { | |
| 111 | + $this->teams[] = $team2; | |
| 112 | + } | |
| 105 | 113 | $team2->groupResults[$this->id] = [ | 
| 106 | 114 | 'group' => $this, | 
| 107 | 115 | 'points' => 0, | 
| @@ -113,8 +121,9 @@ discard block | ||
| 113 | 121 | 'third' => 0 | 
| 114 | 122 | ]; | 
| 115 | 123 | } | 
| 124 | +			} else { | |
| 125 | +				throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 116 | 126 | } | 
| 117 | -			else throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 118 | 127 | } | 
| 119 | 128 | return $this; | 
| 120 | 129 | } | 
| @@ -124,7 +133,9 @@ discard block | ||
| 124 | 133 | return $t; | 
| 125 | 134 | } | 
| 126 | 135 |  	public function getTeams() { | 
| 127 | - if (count($this->teams) > 0) return $this->teams; | |
| 136 | +		if (count($this->teams) > 0) { | |
| 137 | + return $this->teams; | |
| 138 | + } | |
| 128 | 139 | $teams = []; | 
| 129 | 140 |  		foreach ($this->groups as $group) { | 
| 130 | 141 | $teams = array_merge($teams, $group->getTeams()); | 
| @@ -135,7 +146,9 @@ discard block | ||
| 135 | 146 | |
| 136 | 147 |  	public function splitTeams(...$groups) { | 
| 137 | 148 | |
| 138 | - if (count($groups) === 0) $groups = $this->getGroups(); | |
| 149 | +		if (count($groups) === 0) { | |
| 150 | + $groups = $this->getGroups(); | |
| 151 | + } | |
| 139 | 152 | |
| 140 | 153 |  		foreach ($groups as $key => $value) { | 
| 141 | 154 |  			if (gettype($value) === 'array') { | 
| @@ -150,7 +163,9 @@ discard block | ||
| 150 | 163 |  		while (count($teams) > 0) { | 
| 151 | 164 |  			foreach ($groups as $group) { | 
| 152 | 165 |  				if ($group instanceof Group) { | 
| 153 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); | |
| 166 | +					if (count($teams) > 0) { | |
| 167 | + $group->addTeam(array_shift($teams)); | |
| 168 | + } | |
| 154 | 169 | } | 
| 155 | 170 | } | 
| 156 | 171 | } | 
| @@ -165,7 +180,9 @@ discard block | ||
| 165 | 180 | } | 
| 166 | 181 | |
| 167 | 182 |  	public function progressBlank(){ | 
| 168 | - if (!$this->isPlayed()) $this->simulate(); | |
| 183 | +		if (!$this->isPlayed()) { | |
| 184 | + $this->simulate(); | |
| 185 | + } | |
| 169 | 186 |  		foreach ($this->groups as $group) { | 
| 170 | 187 | $group->progressBlank(); | 
| 171 | 188 | } | 
| @@ -174,7 +191,9 @@ discard block | ||
| 174 | 191 | |
| 175 | 192 |  	public function simulate() { | 
| 176 | 193 |  		foreach ($this->groups as $group) { | 
| 177 | - if ($group->isPlayed()) continue; | |
| 194 | +			if ($group->isPlayed()) { | |
| 195 | + continue; | |
| 196 | + } | |
| 178 | 197 | $group->simulate([], false); | 
| 179 | 198 | } | 
| 180 | 199 | return $this; | 
| @@ -45,12 +45,12 @@ | ||
| 45 | 45 | |
| 46 | 46 | private $groups = []; | 
| 47 | 47 | |
| 48 | -	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ | |
| 48 | +	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { | |
| 49 | 49 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); | 
| 50 | 50 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; | 
| 51 | 51 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; | 
| 52 | 52 |  		foreach ($groups as $group) { | 
| 53 | - if ($group instanceof Group) $this->groups[] = $group->id; | |
| 53 | + if ($group instanceof Group) $this->groups[] = $group->id; | |
| 54 | 54 | } | 
| 55 | 55 | } | 
| 56 | 56 |  	public function __toString() { | 
| @@ -46,11 +46,19 @@ discard block | ||
| 46 | 46 | private $groups = []; | 
| 47 | 47 | |
| 48 | 48 |  	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ | 
| 49 | - if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); | |
| 50 | - if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; | |
| 51 | - if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; | |
| 49 | +		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { | |
| 50 | + $this->what = strtolower($what); | |
| 51 | + } | |
| 52 | +		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { | |
| 53 | + $this->how = $how; | |
| 54 | + } | |
| 55 | +		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) { | |
| 56 | + $this->val = $val; | |
| 57 | + } | |
| 52 | 58 |  		foreach ($groups as $group) { | 
| 53 | - if ($group instanceof Group) $this->groups[] = $group->id; | |
| 59 | +			if ($group instanceof Group) { | |
| 60 | + $this->groups[] = $group->id; | |
| 61 | + } | |
| 54 | 62 | } | 
| 55 | 63 | } | 
| 56 | 64 |  	public function __toString() { | 
| @@ -58,37 +66,54 @@ discard block | ||
| 58 | 66 | } | 
| 59 | 67 | |
| 60 | 68 |  	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { | 
| 61 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); | |
| 69 | +		if (count($this->groups) > 0) { | |
| 70 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); | |
| 71 | + } | |
| 62 | 72 |  		if ($this->what == 'team') { | 
| 63 | 73 |  			switch ($this->how) { | 
| 64 | 74 | case '=': | 
| 65 | - if ($this->val === $team) return true; | |
| 75 | +					if ($this->val === $team) { | |
| 76 | + return true; | |
| 77 | + } | |
| 66 | 78 | break; | 
| 67 | 79 | case '!=': | 
| 68 | - if ($this->val !== $team) return true; | |
| 80 | +					if ($this->val !== $team) { | |
| 81 | + return true; | |
| 82 | + } | |
| 69 | 83 | break; | 
| 70 | 84 | } | 
| 71 | 85 | return false; | 
| 72 | - } | |
| 73 | -		elseif ($this->what == 'notprogressed') { | |
| 74 | -			if ($from === null) throw new \Exception('Group $from was not defined.'); | |
| 86 | +		} elseif ($this->what == 'notprogressed') { | |
| 87 | +			if ($from === null) { | |
| 88 | +				throw new \Exception('Group $from was not defined.'); | |
| 89 | + } | |
| 75 | 90 | return !$from->progressed($team); | 
| 76 | - } | |
| 77 | -		elseif ($this->what == 'progressed') { | |
| 78 | -			if ($from === null) throw new \Exception('Group $from was not defined.'); | |
| 91 | +		} elseif ($this->what == 'progressed') { | |
| 92 | +			if ($from === null) { | |
| 93 | +				throw new \Exception('Group $from was not defined.'); | |
| 94 | + } | |
| 79 | 95 | return $from->progressed($team); | 
| 80 | 96 | } | 
| 81 | -		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.'); | |
| 97 | +		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { | |
| 98 | +			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); | |
| 99 | + } | |
| 82 | 100 | $comp = 0; | 
| 83 | 101 |  		if (gettype($groupsId) === 'array' && count($groupsId) > 0) { | 
| 84 | 102 | $sum = 0; | 
| 85 | 103 | $max = null; | 
| 86 | 104 | $min = null; | 
| 87 | 105 |  			foreach ($groupsId as $id) { | 
| 88 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP | |
| 106 | +				if (!isset($team->groupResults[$id])) { | |
| 107 | + continue; | |
| 108 | + } | |
| 109 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP | |
| 89 | 110 | $sum += $team->groupResults[$id][$this->what]; | 
| 90 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; | |
| 91 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; | |
| 111 | +				if ($team->groupResults[$id][$this->what] > $max || $max === null) { | |
| 112 | + $max = $team->groupResults[$id][$this->what]; | |
| 113 | + } | |
| 114 | +				if ($team->groupResults[$id][$this->what] < $min || $min === null) { | |
| 115 | + $min = $team->groupResults[$id][$this->what]; | |
| 116 | + } | |
| 92 | 117 | } | 
| 93 | 118 |  			switch (strtolower($operation)) { | 
| 94 | 119 | case 'sum': | 
| @@ -104,11 +129,9 @@ discard block | ||
| 104 | 129 | $comp = $min; | 
| 105 | 130 | break; | 
| 106 | 131 | } | 
| 107 | - } | |
| 108 | -		elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { | |
| 132 | +		} elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { | |
| 109 | 133 | $comp = $team->groupResults[$groupsId][$this->what]; | 
| 110 | - } | |
| 111 | -		else { | |
| 134 | +		} else { | |
| 112 | 135 |  			throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); | 
| 113 | 136 | } | 
| 114 | 137 | |
| @@ -21,7 +21,7 @@ discard block | ||
| 21 | 21 | $this->name = $name; | 
| 22 | 22 | } | 
| 23 | 23 | |
| 24 | -	public function addRound(Round ...$rounds){ | |
| 24 | +	public function addRound(Round ...$rounds) { | |
| 25 | 25 |  		foreach ($rounds as $round) { | 
| 26 | 26 | if ($round instanceof Round) $this->rounds[] = $round; | 
| 27 | 27 |  			else throw new \Exception('Trying to add round which is not an instance of Round class.'); | 
| @@ -33,15 +33,15 @@ discard block | ||
| 33 | 33 | $this->rounds[] = $r->setSkip($this->allowSkip); | 
| 34 | 34 | return $r; | 
| 35 | 35 | } | 
| 36 | -	public function getRounds(){ | |
| 36 | +	public function getRounds() { | |
| 37 | 37 | return $this->rounds; | 
| 38 | 38 | } | 
| 39 | 39 | |
| 40 | -	public function allowSkip(){ | |
| 40 | +	public function allowSkip() { | |
| 41 | 41 | $this->allowSkip = true; | 
| 42 | 42 | return $this; | 
| 43 | 43 | } | 
| 44 | -	public function disallowSkip(){ | |
| 44 | +	public function disallowSkip() { | |
| 45 | 45 | $this->allowSkip = false; | 
| 46 | 46 | return $this; | 
| 47 | 47 | } | 
| @@ -55,7 +55,7 @@ discard block | ||
| 55 | 55 | |
| 56 | 56 |  	public function addTeam(...$teams) { | 
| 57 | 57 |  		foreach ($teams as $team) { | 
| 58 | -			if ($team instanceof Team)  { | |
| 58 | +			if ($team instanceof Team) { | |
| 59 | 59 | $this->teams[] = $team; | 
| 60 | 60 | } | 
| 61 | 61 |  			elseif (gettype($team) === 'array') { | 
| @@ -23,8 +23,11 @@ discard block | ||
| 23 | 23 | |
| 24 | 24 |  	public function addRound(Round ...$rounds){ | 
| 25 | 25 |  		foreach ($rounds as $round) { | 
| 26 | - if ($round instanceof Round) $this->rounds[] = $round; | |
| 27 | -			else throw new \Exception('Trying to add round which is not an instance of Round class.'); | |
| 26 | +			if ($round instanceof Round) { | |
| 27 | + $this->rounds[] = $round; | |
| 28 | +			} else { | |
| 29 | +				throw new \Exception('Trying to add round which is not an instance of Round class.'); | |
| 30 | + } | |
| 28 | 31 | } | 
| 29 | 32 | return $this; | 
| 30 | 33 | } | 
| @@ -57,13 +60,15 @@ discard block | ||
| 57 | 60 |  		foreach ($teams as $team) { | 
| 58 | 61 |  			if ($team instanceof Team)  { | 
| 59 | 62 | $this->teams[] = $team; | 
| 60 | - } | |
| 61 | -			elseif (gettype($team) === 'array') { | |
| 63 | +			} elseif (gettype($team) === 'array') { | |
| 62 | 64 |  				foreach ($team as $team2) { | 
| 63 | - if ($team2 instanceof Team) $this->teams[] = $team2; | |
| 65 | +					if ($team2 instanceof Team) { | |
| 66 | + $this->teams[] = $team2; | |
| 67 | + } | |
| 64 | 68 | } | 
| 69 | +			} else { | |
| 70 | +				throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 65 | 71 | } | 
| 66 | -			else throw new \Exception('Trying to add team which is not an instance of Team class'); | |
| 67 | 72 | } | 
| 68 | 73 | return $this; | 
| 69 | 74 | } | 
| @@ -73,7 +78,9 @@ discard block | ||
| 73 | 78 | return $t; | 
| 74 | 79 | } | 
| 75 | 80 |  	public function getTeams() { | 
| 76 | - if (count($this->teams) > 0) return $this->teams; | |
| 81 | +		if (count($this->teams) > 0) { | |
| 82 | + return $this->teams; | |
| 83 | + } | |
| 77 | 84 | $teams = []; | 
| 78 | 85 |  		foreach ($this->rounds as $round) { | 
| 79 | 86 | $teams = array_merge($teams, $round->getTeams()); | 
| @@ -92,7 +99,9 @@ discard block | ||
| 92 | 99 | |
| 93 | 100 |  	public function splitTeams(...$rounds) { | 
| 94 | 101 | |
| 95 | - if (count($rounds) === 0) $rounds = $this->getRounds(); | |
| 102 | +		if (count($rounds) === 0) { | |
| 103 | + $rounds = $this->getRounds(); | |
| 104 | + } | |
| 96 | 105 | |
| 97 | 106 | $teams = $this->getTeams(); | 
| 98 | 107 | shuffle($teams); | 
| @@ -112,7 +121,9 @@ discard block | ||
| 112 | 121 | |
| 113 | 122 |  	public function genGamesSimulate() { | 
| 114 | 123 | $games = []; | 
| 115 | -		if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); | |
| 124 | +		if (count($this->rounds) <= 0) { | |
| 125 | +			throw new \Exception('There are no rounds to simulate games from.'); | |
| 126 | + } | |
| 116 | 127 |  		foreach ($this->rounds as $round) { | 
| 117 | 128 | $games = array_merge($games, $round->genGames()); | 
| 118 | 129 | $round->simulate()->progressBlank()->resetGames(); |