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