@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | private static function calcSum(\TournamentGenerator\Team $team, array $groupsId) { |
53 | 53 | $sum = 0; |
54 | 54 | foreach ($groupsId as $id) { |
55 | - if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][self::$what]; |
|
55 | + if (isset($team->groupResults[$id])) { |
|
56 | + $sum += $team->groupResults[$id][self::$what]; |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | return $sum; |
58 | 60 | } |
@@ -62,12 +64,16 @@ discard block |
||
62 | 64 | $games = $team->getGames(null, reset($groupsId)); |
63 | 65 | foreach ($games as $game) { |
64 | 66 | $results = $game->getResults()[$team->getId()]; |
65 | - if (($results[self::$what] > $max || $max === null)) $max = $results[self::$what]; |
|
67 | + if (($results[self::$what] > $max || $max === null)) { |
|
68 | + $max = $results[self::$what]; |
|
69 | + } |
|
66 | 70 | } |
67 | 71 | return $max; |
68 | 72 | } |
69 | 73 | foreach ($groupsId as $id) { |
70 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) $max = $team->groupResults[$id][self::$what]; |
|
74 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) { |
|
75 | + $max = $team->groupResults[$id][self::$what]; |
|
76 | + } |
|
71 | 77 | } |
72 | 78 | return $max; |
73 | 79 | } |
@@ -77,12 +83,16 @@ discard block |
||
77 | 83 | $games = $team->getGames(null, reset($groupsId)); |
78 | 84 | foreach ($games as $game) { |
79 | 85 | $results = $game->getResults()[$team->getId()]; |
80 | - if (($results[self::$what] < $min || $min === null)) $min = $results[self::$what]; |
|
86 | + if (($results[self::$what] < $min || $min === null)) { |
|
87 | + $min = $results[self::$what]; |
|
88 | + } |
|
81 | 89 | } |
82 | 90 | return $min; |
83 | 91 | } |
84 | 92 | foreach ($groupsId as $id) { |
85 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) $min = $team->groupResults[$id][self::$what]; |
|
93 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) { |
|
94 | + $min = $team->groupResults[$id][self::$what]; |
|
95 | + } |
|
86 | 96 | } |
87 | 97 | return $min; |
88 | 98 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $this->setId(isset($id) ? $id : uniqid()); |
19 | 19 | } |
20 | 20 | |
21 | - public function addGroup(Group ...$groups){ |
|
21 | + public function addGroup(Group ...$groups) { |
|
22 | 22 | foreach ($groups as $group) { |
23 | 23 | $this->groups[] = $group; |
24 | 24 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $this->groups[] = $g->setSkip($this->allowSkip); |
30 | 30 | return $g; |
31 | 31 | } |
32 | - public function getGroups(){ |
|
32 | + public function getGroups() { |
|
33 | 33 | $this->orderGroups(); |
34 | 34 | return $this->groups; |
35 | 35 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | return array_map(function($a) { return $a->getId(); }, $this->groups); |
39 | 39 | } |
40 | 40 | public function orderGroups() { |
41 | - usort($this->groups, function($a, $b){ |
|
42 | - return $a->getOrder() - $b->getOrder(); |
|
41 | + usort($this->groups, function($a, $b) { |
|
42 | + return $a->getOrder()-$b->getOrder(); |
|
43 | 43 | }); |
44 | 44 | return $this->groups; |
45 | 45 | } |
46 | 46 | |
47 | - public function allowSkip(){ |
|
47 | + public function allowSkip() { |
|
48 | 48 | $this->allowSkip = true; |
49 | 49 | return $this; |
50 | 50 | } |
51 | - public function disallowSkip(){ |
|
51 | + public function disallowSkip() { |
|
52 | 52 | $this->allowSkip = false; |
53 | 53 | return $this; |
54 | 54 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | return $this->allowSkip; |
61 | 61 | } |
62 | 62 | |
63 | - public function genGames(){ |
|
63 | + public function genGames() { |
|
64 | 64 | foreach ($this->groups as $group) { |
65 | 65 | $group->genGames(); |
66 | 66 | $this->games = array_merge($this->games, $group->orderGames()); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | public function getGames() { |
71 | 71 | return $this->games; |
72 | 72 | } |
73 | - public function isPlayed(){ |
|
73 | + public function isPlayed() { |
|
74 | 74 | if (count($this->games) === 0) return false; |
75 | 75 | foreach ($this->groups as $group) { |
76 | 76 | if (!$group->isPlayed()) return false; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return $this; |
123 | 123 | } |
124 | 124 | |
125 | - public function progress(bool $blank = false){ |
|
125 | + public function progress(bool $blank = false) { |
|
126 | 126 | foreach ($this->groups as $group) { |
127 | 127 | $group->progress($blank); |
128 | 128 | } |
@@ -43,14 +43,14 @@ |
||
43 | 43 | |
44 | 44 | private $groups = []; |
45 | 45 | |
46 | - function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){ |
|
46 | + function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []) { |
|
47 | 47 | if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
48 | 48 | $this->what = strtolower($what); |
49 | 49 | if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
50 | 50 | $this->how = $how; |
51 | 51 | if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')'); |
52 | 52 | $this->val = $val; |
53 | - $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
|
53 | + $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group); })); |
|
54 | 54 | } |
55 | 55 | public function __toString() { |
56 | 56 | return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : ''); |
@@ -44,11 +44,17 @@ discard block |
||
44 | 44 | private $groups = []; |
45 | 45 | |
46 | 46 | function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){ |
47 | - if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
|
47 | + if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
48 | + throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
|
49 | + } |
|
48 | 50 | $this->what = strtolower($what); |
49 | - if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
|
51 | + if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
52 | + throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
|
53 | + } |
|
50 | 54 | $this->how = $how; |
51 | - if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')'); |
|
55 | + if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) { |
|
56 | + throw new \Exception('Unsupported filter value type ('.gettype($val).')'); |
|
57 | + } |
|
52 | 58 | $this->val = $val; |
53 | 59 | $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
54 | 60 | } |
@@ -57,11 +63,17 @@ discard block |
||
57 | 63 | } |
58 | 64 | |
59 | 65 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
60 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
66 | + if (count($this->groups) > 0) { |
|
67 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
68 | + } |
|
61 | 69 | |
62 | - if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
63 | - elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from); |
|
64 | - elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from); |
|
70 | + if ($this->what == 'team') { |
|
71 | + return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
72 | + } elseif ($this->what == 'notprogressed') { |
|
73 | + return !$this->validateProgressed($team, $from); |
|
74 | + } elseif ($this->what == 'progressed') { |
|
75 | + return $this->validateProgressed($team, $from); |
|
76 | + } |
|
65 | 77 | |
66 | 78 | return $this->validateCalc($team, $groupsId, $operation); |
67 | 79 | } |
@@ -70,11 +82,15 @@ discard block |
||
70 | 82 | return $this->val === $team; |
71 | 83 | } |
72 | 84 | private function validateProgressed(Team $team, Group $from = null) { |
73 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
85 | + if ($from === null) { |
|
86 | + throw new \Exception('Group $from was not defined.'); |
|
87 | + } |
|
74 | 88 | return $from->isProgressed($team); |
75 | 89 | } |
76 | 90 | private function validateCalc(Team $team, array $groupsId, string $operation = 'sum') { |
77 | - 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.'); |
|
91 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
92 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
93 | + } |
|
78 | 94 | |
79 | 95 | return Utilis\FilterComparator::compare($operation, $this->val, $this->how, $this->what, $team, $groupsId); |
80 | 96 |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | $this->setId(isset($id) ? $id : uniqid()); |
29 | 29 | } |
30 | 30 | |
31 | - public function allowSkip(){ |
|
31 | + public function allowSkip() { |
|
32 | 32 | $this->generator->allowSkip(); |
33 | 33 | return $this; |
34 | 34 | } |
35 | - public function disallowSkip(){ |
|
35 | + public function disallowSkip() { |
|
36 | 36 | $this->generator->disallowSkip(); |
37 | 37 | return $this; |
38 | 38 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | } |
140 | 140 | } |
141 | 141 | public function addProgressed(...$teams) { |
142 | - $this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($teams, function($a){return $a instanceof Team;}))); |
|
143 | - foreach (array_filter($teams, function($a){return is_array($a);}) as $team) { |
|
144 | - $this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($team, function($a) { |
|
142 | + $this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($teams, function($a) {return $a instanceof Team; }))); |
|
143 | + foreach (array_filter($teams, function($a) {return is_array($a); }) as $team) { |
|
144 | + $this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($team, function($a) { |
|
145 | 145 | return ($a instanceof Team); |
146 | 146 | }))); |
147 | 147 | } |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | $this->games[] = $g; |
162 | 162 | return $g; |
163 | 163 | } |
164 | - public function addGame(...$games){ |
|
165 | - $this->games = array_merge($this->games, array_filter($games, function($a){ return ($a instanceof Game); })); |
|
164 | + public function addGame(...$games) { |
|
165 | + $this->games = array_merge($this->games, array_filter($games, function($a) { return ($a instanceof Game); })); |
|
166 | 166 | |
167 | - foreach (array_filter($games, function($a){return is_array($a);}) as $key => $game) { |
|
168 | - $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
|
167 | + foreach (array_filter($games, function($a) {return is_array($a); }) as $key => $game) { |
|
168 | + $this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); })); |
|
169 | 169 | } |
170 | 170 | return $this; |
171 | 171 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | return $this; |
189 | 189 | } |
190 | - public function isPlayed(){ |
|
190 | + public function isPlayed() { |
|
191 | 191 | if (count($this->games) === 0) return false; |
192 | 192 | foreach ($this->games as $game) { |
193 | 193 | if (!$game->isPlayed()) return false; |