@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | if (gettype($filter) === 'array') { |
30 | 30 | $this->filterMulti($teams, $filter, $key); |
31 | 31 | continue; |
32 | - } |
|
33 | - elseif ($filter instanceof TeamFilter) { |
|
32 | + } elseif ($filter instanceof TeamFilter) { |
|
34 | 33 | $teams = array_filter($teams, function($team) use ($filter) {return $filter->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0]); }); |
35 | 34 | continue; |
36 | 35 | } |
@@ -40,16 +39,24 @@ discard block |
||
40 | 39 | } |
41 | 40 | |
42 | 41 | private function filterMulti(array &$teams, array $filters, string $how = 'and') { |
43 | - if (is_int($how)) $how = 'and'; |
|
42 | + if (is_int($how)) { |
|
43 | + $how = 'and'; |
|
44 | + } |
|
44 | 45 | switch (strtolower($how)) { |
45 | 46 | case 'and': |
46 | 47 | foreach ($teams as $tkey => $team) { |
47 | - if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
48 | + if (!$this->filterAnd($team, $filters)) { |
|
49 | + unset($teams[$tkey]); |
|
50 | + } |
|
51 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
48 | 52 | } |
49 | 53 | return true; |
50 | 54 | case 'or': |
51 | 55 | foreach ($teams as $tkey => $team) { |
52 | - if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
56 | + if (!$this->filterOr($team, $filters)) { |
|
57 | + unset($teams[$tkey]); |
|
58 | + } |
|
59 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
53 | 60 | } |
54 | 61 | return true; |
55 | 62 | } |
@@ -59,21 +66,28 @@ discard block |
||
59 | 66 | private function filterAnd(Team $team, array $filters) { |
60 | 67 | foreach ($filters as $key => $value) { |
61 | 68 | if (is_array($value)) { |
62 | - if (is_int($key)) $key = 'and'; |
|
69 | + if (is_int($key)) { |
|
70 | + $key = 'and'; |
|
71 | + } |
|
63 | 72 | switch (strtolower($key)) { |
64 | 73 | case 'and': |
65 | - if (!$this->filterAnd($team, $value)) return false; |
|
74 | + if (!$this->filterAnd($team, $value)) { |
|
75 | + return false; |
|
76 | + } |
|
66 | 77 | break; |
67 | 78 | case 'or': |
68 | - if (!$this->filterOr($team, $value)) return false; |
|
79 | + if (!$this->filterOr($team, $value)) { |
|
80 | + return false; |
|
81 | + } |
|
69 | 82 | break; |
70 | 83 | default: |
71 | 84 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
72 | 85 | } |
73 | 86 | continue; |
74 | - } |
|
75 | - elseif ($value instanceof TeamFilter) { |
|
76 | - if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return false; |
|
87 | + } elseif ($value instanceof TeamFilter) { |
|
88 | + if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) { |
|
89 | + return false; |
|
90 | + } |
|
77 | 91 | continue; |
78 | 92 | } |
79 | 93 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |
@@ -82,22 +96,29 @@ discard block |
||
82 | 96 | } |
83 | 97 | private function filterOr(Team $team, array $filters) { |
84 | 98 | foreach ($filters as $key => $value) { |
85 | - if (is_int($key)) $key = 'and'; |
|
99 | + if (is_int($key)) { |
|
100 | + $key = 'and'; |
|
101 | + } |
|
86 | 102 | if (is_array($value)) { |
87 | 103 | switch (strtolower($key)) { |
88 | 104 | case 'and': |
89 | - if ($this->filterAnd($team, $value)) return true; |
|
105 | + if ($this->filterAnd($team, $value)) { |
|
106 | + return true; |
|
107 | + } |
|
90 | 108 | break; |
91 | 109 | case 'or': |
92 | - if ($this->filterOr($team, $value)) return true; |
|
110 | + if ($this->filterOr($team, $value)) { |
|
111 | + return true; |
|
112 | + } |
|
93 | 113 | break; |
94 | 114 | default: |
95 | 115 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
96 | 116 | } |
97 | 117 | continue; |
98 | - } |
|
99 | - elseif ($value instanceof TeamFilter) { |
|
100 | - if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return true; |
|
118 | + } elseif ($value instanceof TeamFilter) { |
|
119 | + if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) { |
|
120 | + return true; |
|
121 | + } |
|
101 | 122 | continue; |
102 | 123 | } |
103 | 124 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |
@@ -38,12 +38,20 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | public function progress(bool $blank = false) { |
41 | - if ($this->progressed) return $this; |
|
42 | - if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters); |
|
43 | - else $teams = $this->from->sortTeams(null, $this->filters); |
|
41 | + if ($this->progressed) { |
|
42 | + return $this; |
|
43 | + } |
|
44 | + if ($blank) { |
|
45 | + $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters); |
|
46 | + } else { |
|
47 | + $teams = $this->from->sortTeams(null, $this->filters); |
|
48 | + } |
|
44 | 49 | |
45 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
46 | - else $next = $teams; |
|
50 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
51 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
52 | + } else { |
|
53 | + $next = $teams; |
|
54 | + } |
|
47 | 55 | |
48 | 56 | $i = 1; |
49 | 57 | |
@@ -51,12 +59,15 @@ discard block |
||
51 | 59 | if ($blank) { |
52 | 60 | $this->to->addTeam(new BlankTeam($this.' - '.$i, $team, $this->from, $this)); |
53 | 61 | $i++; |
62 | + } else { |
|
63 | + $team->sumPoints += $this->from->progressPoints; |
|
54 | 64 | } |
55 | - else $team->sumPoints += $this->from->progressPoints; |
|
56 | 65 | } |
57 | 66 | |
58 | 67 | $this->from->addProgressed($next); |
59 | - if (!$blank) $this->to->addTeam($next); |
|
68 | + if (!$blank) { |
|
69 | + $this->to->addTeam($next); |
|
70 | + } |
|
60 | 71 | $this->progressed = true; |
61 | 72 | return $this; |
62 | 73 | } |