@@ -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 | } |
@@ -43,12 +42,18 @@ discard block |
||
| 43 | 42 | switch (strtolower($how)) { |
| 44 | 43 | case 'and': |
| 45 | 44 | foreach ($teams as $tkey => $team) { |
| 46 | - if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 45 | + if (!$this->filterAnd($team, $filters)) { |
|
| 46 | + unset($teams[$tkey]); |
|
| 47 | + } |
|
| 48 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 47 | 49 | } |
| 48 | 50 | return true; |
| 49 | 51 | case 'or': |
| 50 | 52 | foreach ($teams as $tkey => $team) { |
| 51 | - if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 53 | + if (!$this->filterOr($team, $filters)) { |
|
| 54 | + unset($teams[$tkey]); |
|
| 55 | + } |
|
| 56 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 52 | 57 | } |
| 53 | 58 | return true; |
| 54 | 59 | } |
@@ -58,21 +63,28 @@ discard block |
||
| 58 | 63 | private function filterAnd(Team $team, array $filters) { |
| 59 | 64 | foreach ($filters as $key => $value) { |
| 60 | 65 | if (is_array($value)) { |
| 61 | - if (is_int($key)) $key = 'and'; |
|
| 66 | + if (is_int($key)) { |
|
| 67 | + $key = 'and'; |
|
| 68 | + } |
|
| 62 | 69 | switch (strtolower($key)) { |
| 63 | 70 | case 'and': |
| 64 | - if (!$this->filterAnd($team, $value)) return false; |
|
| 71 | + if (!$this->filterAnd($team, $value)) { |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 65 | 74 | break; |
| 66 | 75 | case 'or': |
| 67 | - if (!$this->filterOr($team, $value)) return false; |
|
| 76 | + if (!$this->filterOr($team, $value)) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 68 | 79 | break; |
| 69 | 80 | default: |
| 70 | 81 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 71 | 82 | } |
| 72 | 83 | continue; |
| 73 | - } |
|
| 74 | - elseif ($value instanceof TeamFilter) { |
|
| 75 | - if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return false; |
|
| 84 | + } elseif ($value instanceof TeamFilter) { |
|
| 85 | + if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 76 | 88 | continue; |
| 77 | 89 | } |
| 78 | 90 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |
@@ -81,22 +93,29 @@ discard block |
||
| 81 | 93 | } |
| 82 | 94 | private function filterOr(Team $team, array $filters) { |
| 83 | 95 | foreach ($filters as $key => $value) { |
| 84 | - if (is_int($key)) $key = 'and'; |
|
| 96 | + if (is_int($key)) { |
|
| 97 | + $key = 'and'; |
|
| 98 | + } |
|
| 85 | 99 | if (is_array($value)) { |
| 86 | 100 | switch (strtolower($key)) { |
| 87 | 101 | case 'and': |
| 88 | - if ($this->filterAnd($team, $value)) return true; |
|
| 102 | + if ($this->filterAnd($team, $value)) { |
|
| 103 | + return true; |
|
| 104 | + } |
|
| 89 | 105 | break; |
| 90 | 106 | case 'or': |
| 91 | - if ($this->filterOr($team, $value)) return true; |
|
| 107 | + if ($this->filterOr($team, $value)) { |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 92 | 110 | break; |
| 93 | 111 | default: |
| 94 | 112 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 95 | 113 | } |
| 96 | 114 | continue; |
| 97 | - } |
|
| 98 | - elseif ($value instanceof TeamFilter) { |
|
| 99 | - if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return true; |
|
| 115 | + } elseif ($value instanceof TeamFilter) { |
|
| 116 | + if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) { |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 100 | 119 | continue; |
| 101 | 120 | } |
| 102 | 121 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |