@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | $view = clone $this->view; |
104 | 104 | |
105 | 105 | $filters = []; |
106 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
107 | - if ($schema->hasFilter($name)) { |
|
106 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value){ |
|
107 | + if ($schema->hasFilter($name)){ |
|
108 | 108 | $filter = $schema->getFilter($name)->withValue($value); |
109 | 109 | |
110 | - if ($filter !== null) { |
|
110 | + if ($filter !== null){ |
|
111 | 111 | $source = $this->compiler->compile($source, $filter); |
112 | 112 | $filters[$name] = $filter->getValue(); |
113 | 113 | } |
@@ -115,16 +115,16 @@ discard block |
||
115 | 115 | } |
116 | 116 | $view = $view->withOption(GridInterface::FILTERS, $filters); |
117 | 117 | |
118 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
118 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)){ |
|
119 | 119 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
120 | 120 | } |
121 | 121 | |
122 | 122 | $sorters = []; |
123 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
124 | - if ($schema->hasSorter($name)) { |
|
123 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value){ |
|
124 | + if ($schema->hasSorter($name)){ |
|
125 | 125 | $sorter = $schema->getSorter($name)->withDirection($value); |
126 | 126 | |
127 | - if ($sorter !== null) { |
|
127 | + if ($sorter !== null){ |
|
128 | 128 | $source = $this->compiler->compile($source, $sorter); |
129 | 129 | $sorters[$name] = $sorter->getValue(); |
130 | 130 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | } |
133 | 133 | $view = $view->withOption(GridInterface::SORTERS, $sorters); |
134 | 134 | |
135 | - if ($schema->getPaginator() !== null) { |
|
135 | + if ($schema->getPaginator() !== null){ |
|
136 | 136 | $paginator = $schema->getPaginator()->withValue($this->getOption(static::KEY_PAGINATE)); |
137 | - if ($paginator === null) { |
|
137 | + if ($paginator === null){ |
|
138 | 138 | throw new CompilerException('The paginator can not be null'); |
139 | 139 | } |
140 | 140 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator->getValue()); |
143 | 143 | } |
144 | 144 | |
145 | - if (!is_iterable($source)) { |
|
145 | + if (!is_iterable($source)){ |
|
146 | 146 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
147 | 147 | } |
148 | 148 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | private function getOptionArray(string $option): array |
159 | 159 | { |
160 | 160 | $result = $this->getOption($option); |
161 | - if (!is_array($result)) { |
|
161 | + if (!is_array($result)){ |
|
162 | 162 | return []; |
163 | 163 | } |
164 | 164 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | private function getOption(string $option) |
175 | 175 | { |
176 | - if ($this->input->hasValue($option)) { |
|
176 | + if ($this->input->hasValue($option)){ |
|
177 | 177 | return $this->input->getValue($option); |
178 | 178 | } |
179 | 179 |
@@ -103,11 +103,14 @@ discard block |
||
103 | 103 | $view = clone $this->view; |
104 | 104 | |
105 | 105 | $filters = []; |
106 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
107 | - if ($schema->hasFilter($name)) { |
|
106 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) |
|
107 | + { |
|
108 | + if ($schema->hasFilter($name)) |
|
109 | + { |
|
108 | 110 | $filter = $schema->getFilter($name)->withValue($value); |
109 | 111 | |
110 | - if ($filter !== null) { |
|
112 | + if ($filter !== null) |
|
113 | + { |
|
111 | 114 | $source = $this->compiler->compile($source, $filter); |
112 | 115 | $filters[$name] = $filter->getValue(); |
113 | 116 | } |
@@ -115,16 +118,20 @@ discard block |
||
115 | 118 | } |
116 | 119 | $view = $view->withOption(GridInterface::FILTERS, $filters); |
117 | 120 | |
118 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
121 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) |
|
122 | + { |
|
119 | 123 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
120 | 124 | } |
121 | 125 | |
122 | 126 | $sorters = []; |
123 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
124 | - if ($schema->hasSorter($name)) { |
|
127 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) |
|
128 | + { |
|
129 | + if ($schema->hasSorter($name)) |
|
130 | + { |
|
125 | 131 | $sorter = $schema->getSorter($name)->withDirection($value); |
126 | 132 | |
127 | - if ($sorter !== null) { |
|
133 | + if ($sorter !== null) |
|
134 | + { |
|
128 | 135 | $source = $this->compiler->compile($source, $sorter); |
129 | 136 | $sorters[$name] = $sorter->getValue(); |
130 | 137 | } |
@@ -132,9 +139,11 @@ discard block |
||
132 | 139 | } |
133 | 140 | $view = $view->withOption(GridInterface::SORTERS, $sorters); |
134 | 141 | |
135 | - if ($schema->getPaginator() !== null) { |
|
142 | + if ($schema->getPaginator() !== null) |
|
143 | + { |
|
136 | 144 | $paginator = $schema->getPaginator()->withValue($this->getOption(static::KEY_PAGINATE)); |
137 | - if ($paginator === null) { |
|
145 | + if ($paginator === null) |
|
146 | + { |
|
138 | 147 | throw new CompilerException('The paginator can not be null'); |
139 | 148 | } |
140 | 149 | |
@@ -142,7 +151,8 @@ discard block |
||
142 | 151 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator->getValue()); |
143 | 152 | } |
144 | 153 | |
145 | - if (!is_iterable($source)) { |
|
154 | + if (!is_iterable($source)) |
|
155 | + { |
|
146 | 156 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
147 | 157 | } |
148 | 158 | |
@@ -158,7 +168,8 @@ discard block |
||
158 | 168 | private function getOptionArray(string $option): array |
159 | 169 | { |
160 | 170 | $result = $this->getOption($option); |
161 | - if (!is_array($result)) { |
|
171 | + if (!is_array($result)) |
|
172 | + { |
|
162 | 173 | return []; |
163 | 174 | } |
164 | 175 | |
@@ -173,7 +184,8 @@ discard block |
||
173 | 184 | */ |
174 | 185 | private function getOption(string $option) |
175 | 186 | { |
176 | - if ($this->input->hasValue($option)) { |
|
187 | + if ($this->input->hasValue($option)) |
|
188 | + { |
|
177 | 189 | return $this->input->getValue($option); |
178 | 190 | } |
179 | 191 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function addFilter(string $name, FilterInterface $filter): void |
42 | 42 | { |
43 | - if ($this->hasFilter($name)) { |
|
43 | + if ($this->hasFilter($name)){ |
|
44 | 44 | throw new SchemaException("Filter `$name` is already defined"); |
45 | 45 | } |
46 | 46 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function getFilter(string $name): FilterInterface |
67 | 67 | { |
68 | - if (!$this->hasFilter($name)) { |
|
68 | + if (!$this->hasFilter($name)){ |
|
69 | 69 | throw new SchemaException("No such filter `$name`"); |
70 | 70 | } |
71 | 71 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function addSorter(string $name, SorterInterface $sorter): void |
91 | 91 | { |
92 | - if ($this->hasSorter($name)) { |
|
92 | + if ($this->hasSorter($name)){ |
|
93 | 93 | throw new SchemaException("Sorter `$name` is already defined"); |
94 | 94 | } |
95 | 95 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function getSorter(string $name): SorterInterface |
116 | 116 | { |
117 | - if (!$this->hasSorter($name)) { |
|
117 | + if (!$this->hasSorter($name)){ |
|
118 | 118 | throw new SchemaException("No such sorter `$name`"); |
119 | 119 | } |
120 | 120 |
@@ -40,7 +40,8 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function addFilter(string $name, FilterInterface $filter): void |
42 | 42 | { |
43 | - if ($this->hasFilter($name)) { |
|
43 | + if ($this->hasFilter($name)) |
|
44 | + { |
|
44 | 45 | throw new SchemaException("Filter `$name` is already defined"); |
45 | 46 | } |
46 | 47 | |
@@ -65,7 +66,8 @@ discard block |
||
65 | 66 | */ |
66 | 67 | public function getFilter(string $name): FilterInterface |
67 | 68 | { |
68 | - if (!$this->hasFilter($name)) { |
|
69 | + if (!$this->hasFilter($name)) |
|
70 | + { |
|
69 | 71 | throw new SchemaException("No such filter `$name`"); |
70 | 72 | } |
71 | 73 | |
@@ -89,7 +91,8 @@ discard block |
||
89 | 91 | */ |
90 | 92 | public function addSorter(string $name, SorterInterface $sorter): void |
91 | 93 | { |
92 | - if ($this->hasSorter($name)) { |
|
94 | + if ($this->hasSorter($name)) |
|
95 | + { |
|
93 | 96 | throw new SchemaException("Sorter `$name` is already defined"); |
94 | 97 | } |
95 | 98 | |
@@ -114,7 +117,8 @@ discard block |
||
114 | 117 | */ |
115 | 118 | public function getSorter(string $name): SorterInterface |
116 | 119 | { |
117 | - if (!$this->hasSorter($name)) { |
|
120 | + if (!$this->hasSorter($name)) |
|
121 | + { |
|
118 | 122 | throw new SchemaException("No such sorter `$name`"); |
119 | 123 | } |
120 | 124 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | $sorter = clone $this; |
37 | 37 | $sorter->sorters = []; |
38 | 38 | |
39 | - foreach ($this->sorters as $s) { |
|
39 | + foreach ($this->sorters as $s){ |
|
40 | 40 | $sorter->sorters[] = $s->withDirection($direction); |
41 | 41 | } |
42 | 42 |
@@ -36,7 +36,8 @@ |
||
36 | 36 | $sorter = clone $this; |
37 | 37 | $sorter->sorters = []; |
38 | 38 | |
39 | - foreach ($this->sorters as $s) { |
|
39 | + foreach ($this->sorters as $s) |
|
40 | + { |
|
40 | 41 | $sorter->sorters[] = $s->withDirection($direction); |
41 | 42 | } |
42 | 43 |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $sorter = clone $this; |
48 | 48 | $sorter->direction = $sorter->checkDirection($direction); |
49 | 49 | |
50 | - switch ($sorter->direction) { |
|
50 | + switch ($sorter->direction){ |
|
51 | 51 | case self::ASC: |
52 | 52 | $sorter->sorter = $sorter->asc->withDirection(self::ASC); |
53 | 53 | break; |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function checkDirection($direction): ?string |
78 | 78 | { |
79 | - if (is_string($direction)) { |
|
80 | - if (strtolower($direction) === self::DESC) { |
|
79 | + if (is_string($direction)){ |
|
80 | + if (strtolower($direction) === self::DESC){ |
|
81 | 81 | return self::DESC; |
82 | 82 | } |
83 | 83 | |
84 | - if (strtolower($direction) === self::ASC) { |
|
84 | + if (strtolower($direction) === self::ASC){ |
|
85 | 85 | return self::ASC; |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - if (in_array($direction, ['-1', -1, SORT_DESC], true)) { |
|
89 | + if (in_array($direction, ['-1', -1, SORT_DESC], true)){ |
|
90 | 90 | return self::DESC; |
91 | 91 | } |
92 | 92 | |
93 | - if (in_array($direction, ['1', 1, SORT_ASC], true)) { |
|
93 | + if (in_array($direction, ['1', 1, SORT_ASC], true)){ |
|
94 | 94 | return self::ASC; |
95 | 95 | } |
96 | 96 |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | $sorter = clone $this; |
48 | 48 | $sorter->direction = $sorter->checkDirection($direction); |
49 | 49 | |
50 | - switch ($sorter->direction) { |
|
50 | + switch ($sorter->direction) |
|
51 | + { |
|
51 | 52 | case self::ASC: |
52 | 53 | $sorter->sorter = $sorter->asc->withDirection(self::ASC); |
53 | 54 | break; |
@@ -76,21 +77,26 @@ discard block |
||
76 | 77 | */ |
77 | 78 | private function checkDirection($direction): ?string |
78 | 79 | { |
79 | - if (is_string($direction)) { |
|
80 | - if (strtolower($direction) === self::DESC) { |
|
80 | + if (is_string($direction)) |
|
81 | + { |
|
82 | + if (strtolower($direction) === self::DESC) |
|
83 | + { |
|
81 | 84 | return self::DESC; |
82 | 85 | } |
83 | 86 | |
84 | - if (strtolower($direction) === self::ASC) { |
|
87 | + if (strtolower($direction) === self::ASC) |
|
88 | + { |
|
85 | 89 | return self::ASC; |
86 | 90 | } |
87 | 91 | } |
88 | 92 | |
89 | - if (in_array($direction, ['-1', -1, SORT_DESC], true)) { |
|
93 | + if (in_array($direction, ['-1', -1, SORT_DESC], true)) |
|
94 | + { |
|
90 | 95 | return self::DESC; |
91 | 96 | } |
92 | 97 | |
93 | - if (in_array($direction, ['1', 1, SORT_ASC], true)) { |
|
98 | + if (in_array($direction, ['1', 1, SORT_ASC], true)) |
|
99 | + { |
|
94 | 100 | return self::ASC; |
95 | 101 | } |
96 | 102 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $expression, $value, bool $includeFrom = true, bool $includeTo = true) |
39 | 39 | { |
40 | - if (!$value instanceof ValueInterface && !$this->isValidArray($value)) { |
|
40 | + if (!$value instanceof ValueInterface && !$this->isValidArray($value)){ |
|
41 | 41 | throw new ValueException(sprintf( |
42 | 42 | 'Value expected to be instance of `%s` or an array of 2 different elements, got %s.', |
43 | 43 | ValueInterface::class, |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | public function withValue($value): ?SpecificationInterface |
59 | 59 | { |
60 | 60 | $between = clone $this; |
61 | - if (!$between->value instanceof ValueInterface) { |
|
61 | + if (!$between->value instanceof ValueInterface){ |
|
62 | 62 | // constant value |
63 | 63 | return $between; |
64 | 64 | } |
65 | 65 | |
66 | - if (!$this->isValidArray($value)) { |
|
66 | + if (!$this->isValidArray($value)){ |
|
67 | 67 | // only array of 2 values is expected |
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | 71 | [$from, $to] = $this->convertValue($value); |
72 | - if (!$between->value->accepts($from) || !$between->value->accepts($to)) { |
|
72 | + if (!$between->value->accepts($from) || !$between->value->accepts($to)){ |
|
73 | 73 | return null; |
74 | 74 | } |
75 | 75 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function getFilters(bool $asOriginal = false): array |
103 | 103 | { |
104 | - if ($asOriginal && $this->includeFrom && $this->includeTo) { |
|
104 | + if ($asOriginal && $this->includeFrom && $this->includeTo){ |
|
105 | 105 | return [$this]; |
106 | 106 | } |
107 | 107 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | private function isValidArray($value): bool |
117 | 117 | { |
118 | - if (!is_array($value) || count($value) !== 2) { |
|
118 | + if (!is_array($value) || count($value) !== 2){ |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function invalidValueType($value): string |
132 | 132 | { |
133 | - if (is_object($value)) { |
|
133 | + if (is_object($value)){ |
|
134 | 134 | return get_class($value); |
135 | 135 | } |
136 | 136 | |
137 | - if (is_array($value)) { |
|
137 | + if (is_array($value)){ |
|
138 | 138 | $count = count($value); |
139 | - if ($count === 0) { |
|
139 | + if ($count === 0){ |
|
140 | 140 | return 'empty array'; |
141 | 141 | } |
142 | 142 | |
143 | - if ($count !== 2) { |
|
143 | + if ($count !== 2){ |
|
144 | 144 | return "array of $count elements"; |
145 | 145 | } |
146 | 146 | |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function convertValue($value) |
158 | 158 | { |
159 | - if ($value instanceof ValueInterface) { |
|
159 | + if ($value instanceof ValueInterface){ |
|
160 | 160 | return $value; |
161 | 161 | } |
162 | 162 | |
163 | 163 | $values = array_values($value); |
164 | - if ($values[1] < $values[0]) { |
|
164 | + if ($values[1] < $values[0]){ |
|
165 | 165 | return [$values[1], $values[0]]; |
166 | 166 | } |
167 | 167 |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $expression, $value, bool $includeFrom = true, bool $includeTo = true) |
39 | 39 | { |
40 | - if (!$value instanceof ValueInterface && !$this->isValidArray($value)) { |
|
40 | + if (!$value instanceof ValueInterface && !$this->isValidArray($value)) |
|
41 | + { |
|
41 | 42 | throw new ValueException(sprintf( |
42 | 43 | 'Value expected to be instance of `%s` or an array of 2 different elements, got %s.', |
43 | 44 | ValueInterface::class, |
@@ -58,18 +59,21 @@ discard block |
||
58 | 59 | public function withValue($value): ?SpecificationInterface |
59 | 60 | { |
60 | 61 | $between = clone $this; |
61 | - if (!$between->value instanceof ValueInterface) { |
|
62 | + if (!$between->value instanceof ValueInterface) |
|
63 | + { |
|
62 | 64 | // constant value |
63 | 65 | return $between; |
64 | 66 | } |
65 | 67 | |
66 | - if (!$this->isValidArray($value)) { |
|
68 | + if (!$this->isValidArray($value)) |
|
69 | + { |
|
67 | 70 | // only array of 2 values is expected |
68 | 71 | return null; |
69 | 72 | } |
70 | 73 | |
71 | 74 | [$from, $to] = $this->convertValue($value); |
72 | - if (!$between->value->accepts($from) || !$between->value->accepts($to)) { |
|
75 | + if (!$between->value->accepts($from) || !$between->value->accepts($to)) |
|
76 | + { |
|
73 | 77 | return null; |
74 | 78 | } |
75 | 79 | |
@@ -101,7 +105,8 @@ discard block |
||
101 | 105 | */ |
102 | 106 | public function getFilters(bool $asOriginal = false): array |
103 | 107 | { |
104 | - if ($asOriginal && $this->includeFrom && $this->includeTo) { |
|
108 | + if ($asOriginal && $this->includeFrom && $this->includeTo) |
|
109 | + { |
|
105 | 110 | return [$this]; |
106 | 111 | } |
107 | 112 | |
@@ -115,7 +120,8 @@ discard block |
||
115 | 120 | */ |
116 | 121 | private function isValidArray($value): bool |
117 | 122 | { |
118 | - if (!is_array($value) || count($value) !== 2) { |
|
123 | + if (!is_array($value) || count($value) !== 2) |
|
124 | + { |
|
119 | 125 | return false; |
120 | 126 | } |
121 | 127 | |
@@ -130,17 +136,21 @@ discard block |
||
130 | 136 | */ |
131 | 137 | private function invalidValueType($value): string |
132 | 138 | { |
133 | - if (is_object($value)) { |
|
139 | + if (is_object($value)) |
|
140 | + { |
|
134 | 141 | return get_class($value); |
135 | 142 | } |
136 | 143 | |
137 | - if (is_array($value)) { |
|
144 | + if (is_array($value)) |
|
145 | + { |
|
138 | 146 | $count = count($value); |
139 | - if ($count === 0) { |
|
147 | + if ($count === 0) |
|
148 | + { |
|
140 | 149 | return 'empty array'; |
141 | 150 | } |
142 | 151 | |
143 | - if ($count !== 2) { |
|
152 | + if ($count !== 2) |
|
153 | + { |
|
144 | 154 | return "array of $count elements"; |
145 | 155 | } |
146 | 156 | |
@@ -156,12 +166,14 @@ discard block |
||
156 | 166 | */ |
157 | 167 | private function convertValue($value) |
158 | 168 | { |
159 | - if ($value instanceof ValueInterface) { |
|
169 | + if ($value instanceof ValueInterface) |
|
170 | + { |
|
160 | 171 | return $value; |
161 | 172 | } |
162 | 173 | |
163 | 174 | $values = array_values($value); |
164 | - if ($values[1] < $values[0]) { |
|
175 | + if ($values[1] < $values[0]) |
|
176 | + { |
|
165 | 177 | return [$values[1], $values[0]]; |
166 | 178 | } |
167 | 179 |
@@ -31,10 +31,10 @@ |
||
31 | 31 | public function withValue($value): ?SpecificationInterface |
32 | 32 | { |
33 | 33 | $any = $this->clone($value); |
34 | - foreach ($this->filters as $filter) { |
|
34 | + foreach ($this->filters as $filter){ |
|
35 | 35 | $applied = $filter->withValue($value); |
36 | 36 | |
37 | - if ($applied === null) { |
|
37 | + if ($applied === null){ |
|
38 | 38 | // all nested filters must be configured |
39 | 39 | continue; |
40 | 40 | } |
@@ -31,10 +31,12 @@ |
||
31 | 31 | public function withValue($value): ?SpecificationInterface |
32 | 32 | { |
33 | 33 | $any = $this->clone($value); |
34 | - foreach ($this->filters as $filter) { |
|
34 | + foreach ($this->filters as $filter) |
|
35 | + { |
|
35 | 36 | $applied = $filter->withValue($value); |
36 | 37 | |
37 | - if ($applied === null) { |
|
38 | + if ($applied === null) |
|
39 | + { |
|
38 | 40 | // all nested filters must be configured |
39 | 41 | continue; |
40 | 42 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct($expression, array $value, bool $includeFrom = true, bool $includeTo = true) |
39 | 39 | { |
40 | - if (is_array($expression) || (is_object($expression) && !$expression instanceof ValueInterface)) { |
|
40 | + if (is_array($expression) || (is_object($expression) && !$expression instanceof ValueInterface)){ |
|
41 | 41 | throw new ValueException(sprintf( |
42 | 42 | 'Expression expected to be instance of `%s` or a scalar value, got %s.', |
43 | 43 | ValueInterface::class, |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | )); |
46 | 46 | } |
47 | 47 | |
48 | - if (!$this->isValidArray($value)) { |
|
48 | + if (!$this->isValidArray($value)){ |
|
49 | 49 | throw new ValueException(sprintf( |
50 | 50 | 'Value expected to be an array of 2 different scalar elements, got %s.', |
51 | 51 | $this->invalidValueType($value) |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | public function withValue($value): ?SpecificationInterface |
67 | 67 | { |
68 | 68 | $between = clone $this; |
69 | - if (!$between->expression instanceof ValueInterface) { |
|
69 | + if (!$between->expression instanceof ValueInterface){ |
|
70 | 70 | //constant value |
71 | 71 | return $between; |
72 | 72 | } |
73 | 73 | |
74 | - if (!$between->expression->accepts($value)) { |
|
74 | + if (!$between->expression->accepts($value)){ |
|
75 | 75 | return null; |
76 | 76 | } |
77 | 77 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function getFilters(bool $asOriginal = false): array |
104 | 104 | { |
105 | - if ($asOriginal && $this->includeFrom && $this->includeTo) { |
|
105 | + if ($asOriginal && $this->includeFrom && $this->includeTo){ |
|
106 | 106 | return [$this]; |
107 | 107 | } |
108 | 108 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function isValidArray(array $value): bool |
118 | 118 | { |
119 | - if (count($value) !== 2) { |
|
119 | + if (count($value) !== 2){ |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | private function invalidValueType(array $value): string |
133 | 133 | { |
134 | 134 | $count = count($value); |
135 | - if ($count === 0) { |
|
135 | + if ($count === 0){ |
|
136 | 136 | return 'empty array'; |
137 | 137 | } |
138 | 138 | |
139 | - if ($count !== 2) { |
|
139 | + if ($count !== 2){ |
|
140 | 140 | return "array of $count elements"; |
141 | 141 | } |
142 | 142 | |
143 | 143 | [$from, $to] = array_values($value); |
144 | - if (!is_scalar($from) || !is_scalar($to)) { |
|
144 | + if (!is_scalar($from) || !is_scalar($to)){ |
|
145 | 145 | return 'array of 2 not scalar elements'; |
146 | 146 | } |
147 | 147 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | private function invalidExpressionType($value): string |
156 | 156 | { |
157 | - if (is_object($value)) { |
|
157 | + if (is_object($value)){ |
|
158 | 158 | return get_class($value); |
159 | 159 | } |
160 | 160 |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct($expression, array $value, bool $includeFrom = true, bool $includeTo = true) |
39 | 39 | { |
40 | - if (is_array($expression) || (is_object($expression) && !$expression instanceof ValueInterface)) { |
|
40 | + if (is_array($expression) || (is_object($expression) && !$expression instanceof ValueInterface)) |
|
41 | + { |
|
41 | 42 | throw new ValueException(sprintf( |
42 | 43 | 'Expression expected to be instance of `%s` or a scalar value, got %s.', |
43 | 44 | ValueInterface::class, |
@@ -45,7 +46,8 @@ discard block |
||
45 | 46 | )); |
46 | 47 | } |
47 | 48 | |
48 | - if (!$this->isValidArray($value)) { |
|
49 | + if (!$this->isValidArray($value)) |
|
50 | + { |
|
49 | 51 | throw new ValueException(sprintf( |
50 | 52 | 'Value expected to be an array of 2 different scalar elements, got %s.', |
51 | 53 | $this->invalidValueType($value) |
@@ -66,12 +68,14 @@ discard block |
||
66 | 68 | public function withValue($value): ?SpecificationInterface |
67 | 69 | { |
68 | 70 | $between = clone $this; |
69 | - if (!$between->expression instanceof ValueInterface) { |
|
71 | + if (!$between->expression instanceof ValueInterface) |
|
72 | + { |
|
70 | 73 | //constant value |
71 | 74 | return $between; |
72 | 75 | } |
73 | 76 | |
74 | - if (!$between->expression->accepts($value)) { |
|
77 | + if (!$between->expression->accepts($value)) |
|
78 | + { |
|
75 | 79 | return null; |
76 | 80 | } |
77 | 81 | |
@@ -102,7 +106,8 @@ discard block |
||
102 | 106 | */ |
103 | 107 | public function getFilters(bool $asOriginal = false): array |
104 | 108 | { |
105 | - if ($asOriginal && $this->includeFrom && $this->includeTo) { |
|
109 | + if ($asOriginal && $this->includeFrom && $this->includeTo) |
|
110 | + { |
|
106 | 111 | return [$this]; |
107 | 112 | } |
108 | 113 | |
@@ -116,7 +121,8 @@ discard block |
||
116 | 121 | */ |
117 | 122 | private function isValidArray(array $value): bool |
118 | 123 | { |
119 | - if (count($value) !== 2) { |
|
124 | + if (count($value) !== 2) |
|
125 | + { |
|
120 | 126 | return false; |
121 | 127 | } |
122 | 128 | |
@@ -132,16 +138,19 @@ discard block |
||
132 | 138 | private function invalidValueType(array $value): string |
133 | 139 | { |
134 | 140 | $count = count($value); |
135 | - if ($count === 0) { |
|
141 | + if ($count === 0) |
|
142 | + { |
|
136 | 143 | return 'empty array'; |
137 | 144 | } |
138 | 145 | |
139 | - if ($count !== 2) { |
|
146 | + if ($count !== 2) |
|
147 | + { |
|
140 | 148 | return "array of $count elements"; |
141 | 149 | } |
142 | 150 | |
143 | 151 | [$from, $to] = array_values($value); |
144 | - if (!is_scalar($from) || !is_scalar($to)) { |
|
152 | + if (!is_scalar($from) || !is_scalar($to)) |
|
153 | + { |
|
145 | 154 | return 'array of 2 not scalar elements'; |
146 | 155 | } |
147 | 156 | |
@@ -154,7 +163,8 @@ discard block |
||
154 | 163 | */ |
155 | 164 | private function invalidExpressionType($value): string |
156 | 165 | { |
157 | - if (is_object($value)) { |
|
166 | + if (is_object($value)) |
|
167 | + { |
|
158 | 168 | return get_class($value); |
159 | 169 | } |
160 | 170 |
@@ -38,16 +38,16 @@ |
||
38 | 38 | $select = $this->clone($value); |
39 | 39 | $value = (array)$value; |
40 | 40 | |
41 | - foreach ($this->filters as $name => $filter) { |
|
41 | + foreach ($this->filters as $name => $filter){ |
|
42 | 42 | $name = (string)$name; |
43 | - if (!hasValue($value, $name)) { |
|
43 | + if (!hasValue($value, $name)){ |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $select->filters[$name] = $filter; |
48 | 48 | } |
49 | 49 | |
50 | - if (empty($select->filters)) { |
|
50 | + if (empty($select->filters)){ |
|
51 | 51 | return null; |
52 | 52 | } |
53 | 53 |
@@ -38,16 +38,19 @@ |
||
38 | 38 | $select = $this->clone($value); |
39 | 39 | $value = (array)$value; |
40 | 40 | |
41 | - foreach ($this->filters as $name => $filter) { |
|
41 | + foreach ($this->filters as $name => $filter) |
|
42 | + { |
|
42 | 43 | $name = (string)$name; |
43 | - if (!hasValue($value, $name)) { |
|
44 | + if (!hasValue($value, $name)) |
|
45 | + { |
|
44 | 46 | continue; |
45 | 47 | } |
46 | 48 | |
47 | 49 | $select->filters[$name] = $filter; |
48 | 50 | } |
49 | 51 | |
50 | - if (empty($select->filters)) { |
|
52 | + if (empty($select->filters)) |
|
53 | + { |
|
51 | 54 | return null; |
52 | 55 | } |
53 | 56 |
@@ -31,10 +31,10 @@ |
||
31 | 31 | public function withValue($value): ?SpecificationInterface |
32 | 32 | { |
33 | 33 | $all = $this->clone($value); |
34 | - foreach ($this->filters as $filter) { |
|
34 | + foreach ($this->filters as $filter){ |
|
35 | 35 | $applied = $filter->withValue($value); |
36 | 36 | |
37 | - if ($applied === null) { |
|
37 | + if ($applied === null){ |
|
38 | 38 | // all nested filters must be configured |
39 | 39 | return null; |
40 | 40 | } |
@@ -31,10 +31,12 @@ |
||
31 | 31 | public function withValue($value): ?SpecificationInterface |
32 | 32 | { |
33 | 33 | $all = $this->clone($value); |
34 | - foreach ($this->filters as $filter) { |
|
34 | + foreach ($this->filters as $filter) |
|
35 | + { |
|
35 | 36 | $applied = $filter->withValue($value); |
36 | 37 | |
37 | - if ($applied === null) { |
|
38 | + if ($applied === null) |
|
39 | + { |
|
38 | 40 | // all nested filters must be configured |
39 | 41 | return null; |
40 | 42 | } |