@@ -43,11 +43,11 @@ |
||
| 43 | 43 | |
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
| 46 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
| 47 | 47 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
| 48 | 48 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
| 49 | 49 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
| 50 | - $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
|
| 50 | + $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group); })); |
|
| 51 | 51 | } |
| 52 | 52 | public function __toString() { |
| 53 | 53 | return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : ''); |
@@ -44,9 +44,15 @@ discard block |
||
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | 46 | function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
| 47 | - if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
|
| 48 | - if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
|
| 49 | - if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
|
| 47 | + if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
| 48 | + $this->what = strtolower($what); |
|
| 49 | + } |
|
| 50 | + if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
| 51 | + $this->how = $how; |
|
| 52 | + } |
|
| 53 | + if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) { |
|
| 54 | + $this->val = $val; |
|
| 55 | + } |
|
| 50 | 56 | $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
| 51 | 57 | } |
| 52 | 58 | public function __toString() { |
@@ -54,11 +60,17 @@ discard block |
||
| 54 | 60 | } |
| 55 | 61 | |
| 56 | 62 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
| 57 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 63 | + if (count($this->groups) > 0) { |
|
| 64 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 65 | + } |
|
| 58 | 66 | |
| 59 | - if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
| 60 | - elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from); |
|
| 61 | - elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from); |
|
| 67 | + if ($this->what == 'team') { |
|
| 68 | + return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
| 69 | + } elseif ($this->what == 'notprogressed') { |
|
| 70 | + return !$this->validateProgressed($team, $from); |
|
| 71 | + } elseif ($this->what == 'progressed') { |
|
| 72 | + return $this->validateProgressed($team, $from); |
|
| 73 | + } |
|
| 62 | 74 | |
| 63 | 75 | return $this->validateCalc($team, $groupsId, $operation); |
| 64 | 76 | } |
@@ -67,13 +79,19 @@ discard block |
||
| 67 | 79 | return $this->val === $team; |
| 68 | 80 | } |
| 69 | 81 | private function validateProgressed(Team $team, Group $from = null) { |
| 70 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
| 82 | + if ($from === null) { |
|
| 83 | + throw new \Exception('Group $from was not defined.'); |
|
| 84 | + } |
|
| 71 | 85 | return $from->isProgressed($team); |
| 72 | 86 | } |
| 73 | 87 | private function validateCalc(Team $team, $groupsId, string $operation = 'sum') { |
| 74 | - 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.'); |
|
| 88 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
| 89 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 90 | + } |
|
| 75 | 91 | $comp = 0; |
| 76 | - if (gettype($groupsId) === 'string') $groupsId = [$groupsId]; |
|
| 92 | + if (gettype($groupsId) === 'string') { |
|
| 93 | + $groupsId = [$groupsId]; |
|
| 94 | + } |
|
| 77 | 95 | switch (strtolower($operation)) { |
| 78 | 96 | case 'sum': $comp = $this->calcSum($team, $groupsId); break; |
| 79 | 97 | case 'avg': $comp = $this->calcSum($team, $groupsId)/count($groupsId); break; |
@@ -95,21 +113,27 @@ discard block |
||
| 95 | 113 | private function calcSum(Team $team, $groupsId) { |
| 96 | 114 | $sum = 0; |
| 97 | 115 | foreach ($groupsId as $id) { |
| 98 | - if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][$this->what]; |
|
| 116 | + if (isset($team->groupResults[$id])) { |
|
| 117 | + $sum += $team->groupResults[$id][$this->what]; |
|
| 118 | + } |
|
| 99 | 119 | } |
| 100 | 120 | return $sum; |
| 101 | 121 | } |
| 102 | 122 | private function calcMax(Team $team, $groupsId) { |
| 103 | 123 | $max = null; |
| 104 | 124 | foreach ($groupsId as $id) { |
| 105 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) $max = $team->groupResults[$id][$this->what]; |
|
| 125 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) { |
|
| 126 | + $max = $team->groupResults[$id][$this->what]; |
|
| 127 | + } |
|
| 106 | 128 | } |
| 107 | 129 | return $max; |
| 108 | 130 | } |
| 109 | 131 | private function calcMin(Team $team, $groupsId) { |
| 110 | 132 | $min = null; |
| 111 | 133 | foreach ($groupsId as $id) { |
| 112 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) $min = $team->groupResults[$id][$this->what]; |
|
| 134 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) { |
|
| 135 | + $min = $team->groupResults[$id][$this->what]; |
|
| 136 | + } |
|
| 113 | 137 | } |
| 114 | 138 | return $min; |
| 115 | 139 | } |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * @var array $ids Stores ids of groups get scores and points from |
|
| 22 | - */ |
|
| 21 | + * @var array $ids Stores ids of groups get scores and points from |
|
| 22 | + */ |
|
| 23 | 23 | protected static $ids = []; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * Sort teams in group by defined ordering type |
|
| 27 | - * |
|
| 28 | - * @param array &$teams Array of teams to be sorted |
|
| 29 | - * @param \TournamentGenerator\Group $group Group to get the results from |
|
| 30 | - * @param string $ordering What to order by (\TournamentGenerator\Constants::POINTS / \TournamentGenerator\Constants::SCORE) |
|
| 31 | - * |
|
| 32 | - * @return array Sorted array of teams |
|
| 33 | - */ |
|
| 26 | + * Sort teams in group by defined ordering type |
|
| 27 | + * |
|
| 28 | + * @param array &$teams Array of teams to be sorted |
|
| 29 | + * @param \TournamentGenerator\Group $group Group to get the results from |
|
| 30 | + * @param string $ordering What to order by (\TournamentGenerator\Constants::POINTS / \TournamentGenerator\Constants::SCORE) |
|
| 31 | + * |
|
| 32 | + * @return array Sorted array of teams |
|
| 33 | + */ |
|
| 34 | 34 | public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 35 | 35 | if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
| 36 | 36 | |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * Sort teams in round by defined ordering type |
|
| 53 | - * |
|
| 54 | - * @param array &$teams Array of teams to be sorted |
|
| 55 | - * @param \TournamentGenerator\Round $round Round to get the results from |
|
| 56 | - * @param string $ordering What to order by (\TournamentGenerator\Constants::POINTS / \TournamentGenerator\Constants::SCORE) |
|
| 57 | - * |
|
| 58 | - * @return array Sorted array of teams |
|
| 59 | - */ |
|
| 52 | + * Sort teams in round by defined ordering type |
|
| 53 | + * |
|
| 54 | + * @param array &$teams Array of teams to be sorted |
|
| 55 | + * @param \TournamentGenerator\Round $round Round to get the results from |
|
| 56 | + * @param string $ordering What to order by (\TournamentGenerator\Constants::POINTS / \TournamentGenerator\Constants::SCORE) |
|
| 57 | + * |
|
| 58 | + * @return array Sorted array of teams |
|
| 59 | + */ |
|
| 60 | 60 | public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 61 | 61 | if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
| 62 | 62 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * Sorter function for uasort by points |
|
| 79 | - */ |
|
| 78 | + * Sorter function for uasort by points |
|
| 79 | + */ |
|
| 80 | 80 | private static function sortTeamsByPoints($a, $b) { |
| 81 | 81 | $groupsIds = self::$ids; |
| 82 | 82 | if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
| 85 | 85 | } |
| 86 | 86 | /** |
| 87 | - * Sorter function for uasort by score |
|
| 88 | - */ |
|
| 87 | + * Sorter function for uasort by score |
|
| 88 | + */ |
|
| 89 | 89 | private static function sortTeamsByScore($a, $b) { |
| 90 | 90 | $groupsIds = self::$ids; |
| 91 | 91 | if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
@@ -32,7 +32,9 @@ discard block |
||
| 32 | 32 | * @return array Sorted array of teams |
| 33 | 33 | */ |
| 34 | 34 | public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 35 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 35 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 36 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | self::$ids = [$group->getId()]; |
| 38 | 40 | |
@@ -58,7 +60,9 @@ discard block |
||
| 58 | 60 | * @return array Sorted array of teams |
| 59 | 61 | */ |
| 60 | 62 | public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 61 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 63 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 64 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 65 | + } |
|
| 62 | 66 | |
| 63 | 67 | self::$ids = $round->getGroupsIds(); |
| 64 | 68 | |
@@ -79,8 +83,12 @@ discard block |
||
| 79 | 83 | */ |
| 80 | 84 | private static function sortTeamsByPoints($a, $b) { |
| 81 | 85 | $groupsIds = self::$ids; |
| 82 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 83 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 86 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 87 | + return 0; |
|
| 88 | + } |
|
| 89 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) { |
|
| 90 | + return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 91 | + } |
|
| 84 | 92 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
| 85 | 93 | } |
| 86 | 94 | /** |
@@ -88,7 +96,9 @@ discard block |
||
| 88 | 96 | */ |
| 89 | 97 | private static function sortTeamsByScore($a, $b) { |
| 90 | 98 | $groupsIds = self::$ids; |
| 91 | - if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 99 | + if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 100 | + return 0; |
|
| 101 | + } |
|
| 92 | 102 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
| 93 | 103 | } |
| 94 | 104 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | return $this->id; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function addGroup(Group ...$groups){ |
|
| 43 | + public function addGroup(Group ...$groups) { |
|
| 44 | 44 | foreach ($groups as $group) { |
| 45 | 45 | $this->groups[] = $group; |
| 46 | 46 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $this->groups[] = $g->setSkip($this->allowSkip); |
| 52 | 52 | return $g; |
| 53 | 53 | } |
| 54 | - public function getGroups(){ |
|
| 54 | + public function getGroups() { |
|
| 55 | 55 | $this->orderGroups(); |
| 56 | 56 | return $this->groups; |
| 57 | 57 | } |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | return array_map(function($a) { return $a->getId(); }, $this->groups); |
| 61 | 61 | } |
| 62 | 62 | public function orderGroups() { |
| 63 | - usort($this->groups, function($a, $b){ |
|
| 64 | - return $a->getOrder() - $b->getOrder(); |
|
| 63 | + usort($this->groups, function($a, $b) { |
|
| 64 | + return $a->getOrder()-$b->getOrder(); |
|
| 65 | 65 | }); |
| 66 | 66 | return $this->groups; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function allowSkip(){ |
|
| 69 | + public function allowSkip() { |
|
| 70 | 70 | $this->allowSkip = true; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | - public function disallowSkip(){ |
|
| 73 | + public function disallowSkip() { |
|
| 74 | 74 | $this->allowSkip = false; |
| 75 | 75 | return $this; |
| 76 | 76 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | return $this->allowSkip; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function genGames(){ |
|
| 85 | + public function genGames() { |
|
| 86 | 86 | foreach ($this->groups as $group) { |
| 87 | 87 | $group->genGames(); |
| 88 | 88 | $this->games = array_merge($this->games, $group->orderGames()); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | public function getGames() { |
| 93 | 93 | return $this->games; |
| 94 | 94 | } |
| 95 | - public function isPlayed(){ |
|
| 95 | + public function isPlayed() { |
|
| 96 | 96 | if (count($this->games) === 0) return false; |
| 97 | 97 | foreach ($this->groups as $group) { |
| 98 | 98 | if (!$group->isPlayed()) return false; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | return $this; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public function progress(bool $blank = false){ |
|
| 157 | + public function progress(bool $blank = false) { |
|
| 158 | 158 | foreach ($this->groups as $group) { |
| 159 | 159 | $group->progress($blank); |
| 160 | 160 | } |
@@ -93,9 +93,13 @@ discard block |
||
| 93 | 93 | return $this->games; |
| 94 | 94 | } |
| 95 | 95 | public function isPlayed(){ |
| 96 | - if (count($this->games) === 0) return false; |
|
| 96 | + if (count($this->games) === 0) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 97 | 99 | foreach ($this->groups as $group) { |
| 98 | - if (!$group->isPlayed()) return false; |
|
| 100 | + if (!$group->isPlayed()) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 99 | 103 | } |
| 100 | 104 | return true; |
| 101 | 105 | } |
@@ -134,7 +138,9 @@ discard block |
||
| 134 | 138 | |
| 135 | 139 | public function splitTeams(Group ...$groups) { |
| 136 | 140 | |
| 137 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 141 | + if (count($groups) === 0) { |
|
| 142 | + $groups = $this->getGroups(); |
|
| 143 | + } |
|
| 138 | 144 | |
| 139 | 145 | foreach ($groups as $key => $value) { |
| 140 | 146 | if (gettype($value) === 'array') { |
@@ -148,7 +154,9 @@ discard block |
||
| 148 | 154 | |
| 149 | 155 | while (count($teams) > 0) { |
| 150 | 156 | foreach ($groups as $group) { |
| 151 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 157 | + if (count($teams) > 0) { |
|
| 158 | + $group->addTeam(array_shift($teams)); |
|
| 159 | + } |
|
| 152 | 160 | } |
| 153 | 161 | } |
| 154 | 162 | return $this; |
@@ -75,24 +75,32 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | public function getGroupResults($groupId = null) { |
| 77 | 77 | if (isset($groupId)) { |
| 78 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 78 | + if (!isset($this->groupResults[$groupId])) { |
|
| 79 | + throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 80 | + } |
|
| 79 | 81 | return $this->groupResults[$groupId]; |
| 80 | 82 | } |
| 81 | 83 | return $this->groupResults; |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | public function addGameWith(Team $team, Group $group) { |
| 85 | - if (!isset($this->gamesWith[$group->getId()][$team->getId()])) $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 87 | + if (!isset($this->gamesWith[$group->getId()][$team->getId()])) { |
|
| 88 | + $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 89 | + } |
|
| 86 | 90 | $this->gamesWith[$group->getId()][$team->getId()]++; |
| 87 | 91 | return $this; |
| 88 | 92 | } |
| 89 | 93 | public function addGroup(Group $group) { |
| 90 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 94 | + if (!isset($this->games[$group->getId()])) { |
|
| 95 | + $this->games[$group->getId()] = []; |
|
| 96 | + } |
|
| 91 | 97 | return $this; |
| 92 | 98 | } |
| 93 | 99 | public function addGame(Game $game) { |
| 94 | 100 | $group = $game->getGroup(); |
| 95 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 101 | + if (!isset($this->games[$group->getId()])) { |
|
| 102 | + $this->games[$group->getId()] = []; |
|
| 103 | + } |
|
| 96 | 104 | $this->games[$group->getId()][] = $game; |
| 97 | 105 | return $this; |
| 98 | 106 | } |
@@ -105,88 +113,116 @@ discard block |
||
| 105 | 113 | } |
| 106 | 114 | |
| 107 | 115 | public function addWin(string $groupId = ''){ |
| 108 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 116 | + if (!isset($this->groupResults[$groupId])) { |
|
| 117 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 118 | + } |
|
| 109 | 119 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 110 | 120 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 111 | 121 | $this->groupResults[$groupId]['wins']++; |
| 112 | 122 | return $this; |
| 113 | 123 | } |
| 114 | 124 | public function removeWin(string $groupId = ''){ |
| 115 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 125 | + if (!isset($this->groupResults[$groupId])) { |
|
| 126 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 127 | + } |
|
| 116 | 128 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 117 | 129 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 118 | 130 | $this->groupResults[$groupId]['wins']--; |
| 119 | 131 | return $this; |
| 120 | 132 | } |
| 121 | 133 | public function addDraw(string $groupId = ''){ |
| 122 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 134 | + if (!isset($this->groupResults[$groupId])) { |
|
| 135 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 136 | + } |
|
| 123 | 137 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 124 | 138 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 125 | 139 | $this->groupResults[$groupId]['draws']++; |
| 126 | 140 | return $this; |
| 127 | 141 | } |
| 128 | 142 | public function removeDraw(string $groupId = ''){ |
| 129 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 143 | + if (!isset($this->groupResults[$groupId])) { |
|
| 144 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 145 | + } |
|
| 130 | 146 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 131 | 147 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 132 | 148 | $this->groupResults[$groupId]['draws']--; |
| 133 | 149 | return $this; |
| 134 | 150 | } |
| 135 | 151 | public function addLoss(string $groupId = ''){ |
| 136 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 152 | + if (!isset($this->groupResults[$groupId])) { |
|
| 153 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 154 | + } |
|
| 137 | 155 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 138 | 156 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 139 | 157 | $this->groupResults[$groupId]['losses']++; |
| 140 | 158 | return $this; |
| 141 | 159 | } |
| 142 | 160 | public function removeLoss(string $groupId = ''){ |
| 143 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 161 | + if (!isset($this->groupResults[$groupId])) { |
|
| 162 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 163 | + } |
|
| 144 | 164 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 145 | 165 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 146 | 166 | $this->groupResults[$groupId]['losses']--; |
| 147 | 167 | return $this; |
| 148 | 168 | } |
| 149 | 169 | public function addSecond(string $groupId = ''){ |
| 150 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 170 | + if (!isset($this->groupResults[$groupId])) { |
|
| 171 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 172 | + } |
|
| 151 | 173 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 152 | 174 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 153 | 175 | $this->groupResults[$groupId]['second']++; |
| 154 | 176 | return $this; |
| 155 | 177 | } |
| 156 | 178 | public function removeSecond(string $groupId = ''){ |
| 157 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 179 | + if (!isset($this->groupResults[$groupId])) { |
|
| 180 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 181 | + } |
|
| 158 | 182 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 159 | 183 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 160 | 184 | $this->groupResults[$groupId]['second']--; |
| 161 | 185 | return $this; |
| 162 | 186 | } |
| 163 | 187 | public function addThird(string $groupId = ''){ |
| 164 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 188 | + if (!isset($this->groupResults[$groupId])) { |
|
| 189 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 190 | + } |
|
| 165 | 191 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 166 | 192 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 167 | 193 | $this->groupResults[$groupId]['third']++; |
| 168 | 194 | return $this; |
| 169 | 195 | } |
| 170 | 196 | public function removeThird(string $groupId = ''){ |
| 171 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 197 | + if (!isset($this->groupResults[$groupId])) { |
|
| 198 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 199 | + } |
|
| 172 | 200 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 173 | 201 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 174 | 202 | $this->groupResults[$groupId]['third']--; |
| 175 | 203 | return $this; |
| 176 | 204 | } |
| 177 | 205 | public function sumPoints(array $groupIds = []) { |
| 178 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
| 206 | + if (count($groupIds) === 0) { |
|
| 207 | + return $this->sumPoints; |
|
| 208 | + } |
|
| 179 | 209 | $sum = 0; |
| 180 | 210 | foreach ($groupIds as $gid) { |
| 181 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['points']; |
|
| 211 | + if (isset($this->groupResults[$gid])) { |
|
| 212 | + $sum += $this->groupResults[$gid]['points']; |
|
| 213 | + } |
|
| 182 | 214 | } |
| 183 | 215 | return $sum; |
| 184 | 216 | } |
| 185 | 217 | public function sumScore(array $groupIds = []) { |
| 186 | - if (count($groupIds) === 0) return $this->sumScore; |
|
| 218 | + if (count($groupIds) === 0) { |
|
| 219 | + return $this->sumScore; |
|
| 220 | + } |
|
| 187 | 221 | $sum = 0; |
| 188 | 222 | foreach ($groupIds as $gid) { |
| 189 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['score']; |
|
| 223 | + if (isset($this->groupResults[$gid])) { |
|
| 224 | + $sum += $this->groupResults[$gid]['score']; |
|
| 225 | + } |
|
| 190 | 226 | } |
| 191 | 227 | return $sum; |
| 192 | 228 | } |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | return $this->id; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function allowSkip(){ |
|
| 53 | + public function allowSkip() { |
|
| 54 | 54 | $this->generator->allowSkip(); |
| 55 | 55 | return $this; |
| 56 | 56 | } |
| 57 | - public function disallowSkip(){ |
|
| 57 | + public function disallowSkip() { |
|
| 58 | 58 | $this->generator->disallowSkip(); |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | $this->games[] = $g; |
| 189 | 189 | return $g; |
| 190 | 190 | } |
| 191 | - public function addGame(...$games){ |
|
| 191 | + public function addGame(...$games) { |
|
| 192 | 192 | foreach ($games as $key => $game) { |
| 193 | 193 | if (gettype($game) === 'array') { |
| 194 | 194 | unset($games[$key]); |
| 195 | - $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
|
| 195 | + $this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); })); |
|
| 196 | 196 | continue; |
| 197 | 197 | } |
| 198 | 198 | if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.'); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | return $this; |
| 220 | 220 | } |
| 221 | - public function isPlayed(){ |
|
| 221 | + public function isPlayed() { |
|
| 222 | 222 | if (count($this->games) === 0) return false; |
| 223 | 223 | foreach ($this->games as $game) { |
| 224 | 224 | if (!$game->isPlayed()) return false; |
@@ -86,8 +86,11 @@ discard block |
||
| 86 | 86 | public function getTeams(array $filters = []) { |
| 87 | 87 | $teams = $this->teams; |
| 88 | 88 | |
| 89 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
| 90 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
| 89 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
| 90 | + $filters = [$filters]; |
|
| 91 | + } elseif (gettype($filters) !== 'array') { |
|
| 92 | + $filters = []; |
|
| 93 | + } |
|
| 91 | 94 | |
| 92 | 95 | // APPLY FILTERS |
| 93 | 96 | $filter = new Filter($this, $filters); |
@@ -103,7 +106,9 @@ discard block |
||
| 103 | 106 | return $t; |
| 104 | 107 | } |
| 105 | 108 | public function sortTeams(array $filters = [], $ordering = null) { |
| 106 | - if (!isset($ordering)) $ordering = $this->ordering; |
|
| 109 | + if (!isset($ordering)) { |
|
| 110 | + $ordering = $this->ordering; |
|
| 111 | + } |
|
| 107 | 112 | Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering); |
| 108 | 113 | return $this->getTeams($filters); |
| 109 | 114 | } |
@@ -133,7 +138,9 @@ discard block |
||
| 133 | 138 | } |
| 134 | 139 | |
| 135 | 140 | public function setOrdering(string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 136 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 141 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 142 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 143 | + } |
|
| 137 | 144 | $this->ordering = $ordering; |
| 138 | 145 | return $this; |
| 139 | 146 | } |
@@ -165,8 +172,9 @@ discard block |
||
| 165 | 172 | } |
| 166 | 173 | public function addProgressed(...$teams) { |
| 167 | 174 | foreach ($teams as $team) { |
| 168 | - if ($team instanceOf Team) $this->progressed[] = $team; |
|
| 169 | - elseif (gettype($team) === 'array') { |
|
| 175 | + if ($team instanceOf Team) { |
|
| 176 | + $this->progressed[] = $team; |
|
| 177 | + } elseif (gettype($team) === 'array') { |
|
| 170 | 178 | $this->progressed = array_merge($this->progressed, array_filter($team, function($a) { |
| 171 | 179 | return ($a instanceof Team); |
| 172 | 180 | })); |
@@ -195,7 +203,9 @@ discard block |
||
| 195 | 203 | $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
| 196 | 204 | continue; |
| 197 | 205 | } |
| 198 | - if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 206 | + if (!$game instanceof Game) { |
|
| 207 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 208 | + } |
|
| 199 | 209 | $this->games[] = $game; |
| 200 | 210 | } |
| 201 | 211 | return $this; |
@@ -204,7 +214,9 @@ discard block |
||
| 204 | 214 | return $this->games; |
| 205 | 215 | } |
| 206 | 216 | public function orderGames() { |
| 207 | - if (count($this->games) <= 4) return $this->games; |
|
| 217 | + if (count($this->games) <= 4) { |
|
| 218 | + return $this->games; |
|
| 219 | + } |
|
| 208 | 220 | $this->games = $this->generator->orderGames(); |
| 209 | 221 | return $this->games; |
| 210 | 222 | } |
@@ -219,9 +231,13 @@ discard block |
||
| 219 | 231 | return $this; |
| 220 | 232 | } |
| 221 | 233 | public function isPlayed(){ |
| 222 | - if (count($this->games) === 0) return false; |
|
| 234 | + if (count($this->games) === 0) { |
|
| 235 | + return false; |
|
| 236 | + } |
|
| 223 | 237 | foreach ($this->games as $game) { |
| 224 | - if (!$game->isPlayed()) return false; |
|
| 238 | + if (!$game->isPlayed()) { |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 225 | 241 | } |
| 226 | 242 | return true; |
| 227 | 243 | } |
@@ -25,8 +25,7 @@ discard block |
||
| 25 | 25 | if (gettype($filter) === 'array') { |
| 26 | 26 | $this->filterMulti($teams, $filter, $key); |
| 27 | 27 | continue; |
| 28 | - } |
|
| 29 | - elseif ($filter instanceof TeamFilter) { |
|
| 28 | + } elseif ($filter instanceof TeamFilter) { |
|
| 30 | 29 | $teams = array_filter($teams, function($team) use ($filter) {return $filter->validate($team, $this->group->getId(), 'sum', $this->group); }); |
| 31 | 30 | continue; |
| 32 | 31 | } |
@@ -39,12 +38,18 @@ discard block |
||
| 39 | 38 | switch (strtolower($how)) { |
| 40 | 39 | case 'and': |
| 41 | 40 | foreach ($teams as $tkey => $team) { |
| 42 | - if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 41 | + if (!$this->filterAnd($team, $filters)) { |
|
| 42 | + unset($teams[$tkey]); |
|
| 43 | + } |
|
| 44 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 43 | 45 | } |
| 44 | 46 | return true; |
| 45 | 47 | case 'or': |
| 46 | 48 | foreach ($teams as $tkey => $team) { |
| 47 | - if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 49 | + if (!$this->filterOr($team, $filters)) { |
|
| 50 | + unset($teams[$tkey]); |
|
| 51 | + } |
|
| 52 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 48 | 53 | } |
| 49 | 54 | return true; |
| 50 | 55 | } |
@@ -56,19 +61,24 @@ discard block |
||
| 56 | 61 | if (gettype($value) === 'array') { |
| 57 | 62 | switch (strtolower($key)) { |
| 58 | 63 | case 'and': |
| 59 | - if ($this->filterAnd($team, $value)) return false; |
|
| 64 | + if ($this->filterAnd($team, $value)) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 60 | 67 | break; |
| 61 | 68 | case 'or': |
| 62 | - if ($this->filterOr($team, $value)) return false; |
|
| 69 | + if ($this->filterOr($team, $value)) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 63 | 72 | break; |
| 64 | 73 | default: |
| 65 | 74 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 66 | 75 | break; |
| 67 | 76 | } |
| 68 | 77 | continue; |
| 69 | - } |
|
| 70 | - elseif ($value instanceof TeamFilter) { |
|
| 71 | - if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) return false; |
|
| 78 | + } elseif ($value instanceof TeamFilter) { |
|
| 79 | + if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 72 | 82 | continue; |
| 73 | 83 | } |
| 74 | 84 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
@@ -80,19 +90,24 @@ discard block |
||
| 80 | 90 | if (gettype($value) === 'array') { |
| 81 | 91 | switch (strtolower($key)) { |
| 82 | 92 | case 'and': |
| 83 | - if ($this->filterAnd($team, $value)) return true; |
|
| 93 | + if ($this->filterAnd($team, $value)) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 84 | 96 | break; |
| 85 | 97 | case 'or': |
| 86 | - if ($this->filterOr($team, $value)) return true; |
|
| 98 | + if ($this->filterOr($team, $value)) { |
|
| 99 | + return true; |
|
| 100 | + } |
|
| 87 | 101 | break; |
| 88 | 102 | default: |
| 89 | 103 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 90 | 104 | break; |
| 91 | 105 | } |
| 92 | 106 | continue; |
| 93 | - } |
|
| 94 | - elseif ($value instanceof TeamFilter) { |
|
| 95 | - if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) return true; |
|
| 107 | + } elseif ($value instanceof TeamFilter) { |
|
| 108 | + if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) { |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 96 | 111 | continue; |
| 97 | 112 | } |
| 98 | 113 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
@@ -80,10 +80,10 @@ |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * $results = array ( |
|
| 84 | - * * team->getId() => team->score |
|
| 85 | - * ) |
|
| 86 | - */ |
|
| 83 | + * $results = array ( |
|
| 84 | + * * team->getId() => team->score |
|
| 85 | + * ) |
|
| 86 | + */ |
|
| 87 | 87 | public function setResults(array $results = []) { |
| 88 | 88 | if (count($this->results) === 0) $this->resetResults(); |
| 89 | 89 | arsort($results); |
@@ -66,11 +66,11 @@ |
||
| 66 | 66 | if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | - public function getTeams(){ |
|
| 69 | + public function getTeams() { |
|
| 70 | 70 | return $this->teams; |
| 71 | 71 | } |
| 72 | - public function getTeamsIds(){ |
|
| 73 | - return array_map(function($a){ return $a->getId(); }, $this->teams); |
|
| 72 | + public function getTeamsIds() { |
|
| 73 | + return array_map(function($a) { return $a->getId(); }, $this->teams); |
|
| 74 | 74 | } |
| 75 | 75 | public function getTeam(string $id) { |
| 76 | 76 | foreach ($this->teams as $team) { |
@@ -33,11 +33,15 @@ discard block |
||
| 33 | 33 | $this->teams = $teams; |
| 34 | 34 | foreach ($this->teams as $team) { |
| 35 | 35 | foreach ($this->teams as $team2) { |
| 36 | - if ($team === $team2) continue; |
|
| 36 | + if ($team === $team2) { |
|
| 37 | + continue; |
|
| 38 | + } |
|
| 37 | 39 | $team->addGameWith($team2, $group); |
| 38 | 40 | } |
| 39 | 41 | } |
| 40 | - 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)); |
|
| 42 | + if (count($error) > 0) { |
|
| 43 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 44 | + } |
|
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | public function getGroup() { |
@@ -56,14 +60,18 @@ discard block |
||
| 56 | 60 | $team->addGame($this); |
| 57 | 61 | |
| 58 | 62 | foreach ($this->teams as $team2) { |
| 59 | - if ($team === $team2) continue; |
|
| 63 | + if ($team === $team2) { |
|
| 64 | + continue; |
|
| 65 | + } |
|
| 60 | 66 | if ($team instanceof Team) { |
| 61 | 67 | $team->addGameWith($team2, $this->group); |
| 62 | 68 | $team2->addGameWith($team, $this->group); |
| 63 | 69 | } |
| 64 | 70 | } |
| 65 | 71 | } |
| 66 | - if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 72 | + if (count($error) > 0) { |
|
| 73 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 74 | + } |
|
| 67 | 75 | return $this; |
| 68 | 76 | } |
| 69 | 77 | public function getTeams(){ |
@@ -74,7 +82,9 @@ discard block |
||
| 74 | 82 | } |
| 75 | 83 | public function getTeam(string $id) { |
| 76 | 84 | foreach ($this->teams as $team) { |
| 77 | - if ($team->getId() === $id) return $team; |
|
| 85 | + if ($team->getId() === $id) { |
|
| 86 | + return $team; |
|
| 87 | + } |
|
| 78 | 88 | } |
| 79 | 89 | return false; |
| 80 | 90 | } |
@@ -85,13 +95,17 @@ discard block |
||
| 85 | 95 | * ) |
| 86 | 96 | */ |
| 87 | 97 | public function setResults(array $results = []) { |
| 88 | - if (count($this->results) === 0) $this->resetResults(); |
|
| 98 | + if (count($this->results) === 0) { |
|
| 99 | + $this->resetResults(); |
|
| 100 | + } |
|
| 89 | 101 | arsort($results); |
| 90 | 102 | $inGame = /** @scrutinizer ignore-call */ $this->group->getInGame(); |
| 91 | 103 | $i = 1; |
| 92 | 104 | foreach ($results as $id => $score) { |
| 93 | 105 | $team = $this->getTeam($id); |
| 94 | - if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 106 | + if ($team === false) { |
|
| 107 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 108 | + } |
|
| 95 | 109 | $this->results[$team->getId()] = ['score' => $score]; |
| 96 | 110 | $team->sumScore += $score; |
| 97 | 111 | $prev = prev($results); |
@@ -118,13 +132,11 @@ discard block |
||
| 118 | 132 | $this->drawIds[] = $team->getId(); |
| 119 | 133 | $team->addDraw($this->group->getId()); |
| 120 | 134 | $this->results[$team->getId()] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
| 121 | - } |
|
| 122 | - elseif ($i === 1) { |
|
| 135 | + } elseif ($i === 1) { |
|
| 123 | 136 | $this->winId = $team->getId(); |
| 124 | 137 | $team->addWin($this->group->getId()); |
| 125 | 138 | $this->results[$team->getId()] += ['points' => $this->group->winPoints, 'type' => 'win']; |
| 126 | - } |
|
| 127 | - else { |
|
| 139 | + } else { |
|
| 128 | 140 | $this->lossId = $team->getId(); |
| 129 | 141 | $team->addLoss($this->group->getId()); |
| 130 | 142 | $this->results[$team->getId()] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -223,7 +235,9 @@ discard block |
||
| 223 | 235 | } |
| 224 | 236 | |
| 225 | 237 | public function isPlayed() { |
| 226 | - if (count($this->results) > 0) return true; |
|
| 238 | + if (count($this->results) > 0) { |
|
| 239 | + return true; |
|
| 240 | + } |
|
| 227 | 241 | return false; |
| 228 | 242 | } |
| 229 | 243 | } |