@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $expected, |
| 242 | 242 | string $expectedException = null |
| 243 | 243 | ): void { |
| 244 | - if ($expectedException !== null) { |
|
| 244 | + if ($expectedException !== null){ |
|
| 245 | 245 | $this->expectException($expectedException); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | new Gte('price', new Value\FloatValue()) |
| 301 | 301 | ); |
| 302 | 302 | $schema->addWrappedFilters( |
| 303 | - static function (FilterInterface ...$filters) { |
|
| 303 | + static function (FilterInterface ...$filters){ |
|
| 304 | 304 | return new Any(...$filters); |
| 305 | 305 | }, |
| 306 | 306 | 'size', |
@@ -372,15 +372,15 @@ discard block |
||
| 372 | 372 | private function paginatorInput(int $page = null, int $limit = null): array |
| 373 | 373 | { |
| 374 | 374 | $result = []; |
| 375 | - if ($page === null && $limit === null) { |
|
| 375 | + if ($page === null && $limit === null){ |
|
| 376 | 376 | return $result; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ($page !== null) { |
|
| 379 | + if ($page !== null){ |
|
| 380 | 380 | $result['page'] = $page; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if ($limit !== null) { |
|
| 383 | + if ($limit !== null){ |
|
| 384 | 384 | $result['limit'] = $limit; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -241,7 +241,8 @@ discard block |
||
| 241 | 241 | $expected, |
| 242 | 242 | string $expectedException = null |
| 243 | 243 | ): void { |
| 244 | - if ($expectedException !== null) { |
|
| 244 | + if ($expectedException !== null) |
|
| 245 | + { |
|
| 245 | 246 | $this->expectException($expectedException); |
| 246 | 247 | } |
| 247 | 248 | |
@@ -300,7 +301,8 @@ discard block |
||
| 300 | 301 | new Gte('price', new Value\FloatValue()) |
| 301 | 302 | ); |
| 302 | 303 | $schema->addWrappedFilters( |
| 303 | - static function (FilterInterface ...$filters) { |
|
| 304 | + static function (FilterInterface ...$filters) |
|
| 305 | + { |
|
| 304 | 306 | return new Any(...$filters); |
| 305 | 307 | }, |
| 306 | 308 | 'size', |
@@ -372,15 +374,18 @@ discard block |
||
| 372 | 374 | private function paginatorInput(int $page = null, int $limit = null): array |
| 373 | 375 | { |
| 374 | 376 | $result = []; |
| 375 | - if ($page === null && $limit === null) { |
|
| 377 | + if ($page === null && $limit === null) |
|
| 378 | + { |
|
| 376 | 379 | return $result; |
| 377 | 380 | } |
| 378 | 381 | |
| 379 | - if ($page !== null) { |
|
| 382 | + if ($page !== null) |
|
| 383 | + { |
|
| 380 | 384 | $result['page'] = $page; |
| 381 | 385 | } |
| 382 | 386 | |
| 383 | - if ($limit !== null) { |
|
| 387 | + if ($limit !== null) |
|
| 388 | + { |
|
| 384 | 389 | $result['limit'] = $limit; |
| 385 | 390 | } |
| 386 | 391 | |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
| 23 | 23 | { |
| 24 | - if (is_array($source)) { |
|
| 24 | + if (is_array($source)){ |
|
| 25 | 25 | $source[] = $specification; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -21,7 +21,8 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
| 23 | 23 | { |
| 24 | - if (is_array($source)) { |
|
| 24 | + if (is_array($source)) |
|
| 25 | + { |
|
| 25 | 26 | $source[] = $specification; |
| 26 | 27 | } |
| 27 | 28 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | ['view' => $view, 'source' => $source] = $this->applySorters($view, $source, $schema); |
| 109 | 109 | ['view' => $view, 'source' => $source] = $this->applyPaginator($view, $source, $schema); |
| 110 | 110 | |
| 111 | - if (!is_iterable($source)) { |
|
| 111 | + if (!is_iterable($source)){ |
|
| 112 | 112 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | $values = []; |
| 129 | 129 | $filters = []; |
| 130 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
| 131 | - if ($schema->hasFilter($name)) { |
|
| 130 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value){ |
|
| 131 | + if ($schema->hasFilter($name)){ |
|
| 132 | 132 | $filter = $schema->getFilter($name)->withValue($value); |
| 133 | 133 | |
| 134 | - if ($filter !== null) { |
|
| 134 | + if ($filter !== null){ |
|
| 135 | 135 | $filters[$name] = $filter; |
| 136 | 136 | $values[$name] = $filter->getValue(); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - foreach ($schema->wrapFilters($filters) as $filter) { |
|
| 141 | + foreach ($schema->wrapFilters($filters) as $filter){ |
|
| 142 | 142 | $source = $this->compiler->compile($source, $filter); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | protected function applyCounter(GridInterface $view, $source, GridSchema $schema): array |
| 149 | 149 | { |
| 150 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
| 150 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)){ |
|
| 151 | 151 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -165,11 +165,11 @@ discard block |
||
| 165 | 165 | protected function getSorters($source, GridSchema $schema): array |
| 166 | 166 | { |
| 167 | 167 | $sorters = []; |
| 168 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
| 169 | - if ($schema->hasSorter($name)) { |
|
| 168 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value){ |
|
| 169 | + if ($schema->hasSorter($name)){ |
|
| 170 | 170 | $sorter = $schema->getSorter($name)->withDirection($value); |
| 171 | 171 | |
| 172 | - if ($sorter !== null) { |
|
| 172 | + if ($sorter !== null){ |
|
| 173 | 173 | $source = $this->compiler->compile($source, $sorter); |
| 174 | 174 | $sorters[$name] = $sorter->getValue(); |
| 175 | 175 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | protected function applyPaginator(GridInterface $view, $source, GridSchema $schema): array |
| 183 | 183 | { |
| 184 | - if ($schema->getPaginator() !== null) { |
|
| 184 | + if ($schema->getPaginator() !== null){ |
|
| 185 | 185 | ['source' => $source, 'paginator' => $paginator] = $this->getPaginator($source, $schema); |
| 186 | 186 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator); |
| 187 | 187 | } |
@@ -192,12 +192,12 @@ discard block |
||
| 192 | 192 | protected function getPaginator($source, GridSchema $schema): array |
| 193 | 193 | { |
| 194 | 194 | $paginator = $schema->getPaginator(); |
| 195 | - if (!$paginator instanceof FilterInterface) { |
|
| 195 | + if (!$paginator instanceof FilterInterface){ |
|
| 196 | 196 | throw new CompilerException('Paginator can not be null'); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $withValue = $paginator->withValue($this->getOption(static::KEY_PAGINATE)); |
| 200 | - if ($withValue === null) { |
|
| 200 | + if ($withValue === null){ |
|
| 201 | 201 | throw new CompilerException('Paginator can not be null'); |
| 202 | 202 | } |
| 203 | 203 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | protected function getOptionArray(string $option): array |
| 217 | 217 | { |
| 218 | 218 | $result = $this->getOption($option); |
| 219 | - if (!is_array($result)) { |
|
| 219 | + if (!is_array($result)){ |
|
| 220 | 220 | return []; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | protected function getOption(string $option) |
| 233 | 233 | { |
| 234 | - if ($this->input->hasValue($option)) { |
|
| 234 | + if ($this->input->hasValue($option)){ |
|
| 235 | 235 | return $this->input->getValue($option); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -108,7 +108,8 @@ discard block |
||
| 108 | 108 | ['view' => $view, 'source' => $source] = $this->applySorters($view, $source, $schema); |
| 109 | 109 | ['view' => $view, 'source' => $source] = $this->applyPaginator($view, $source, $schema); |
| 110 | 110 | |
| 111 | - if (!is_iterable($source)) { |
|
| 111 | + if (!is_iterable($source)) |
|
| 112 | + { |
|
| 112 | 113 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -127,18 +128,22 @@ discard block |
||
| 127 | 128 | { |
| 128 | 129 | $values = []; |
| 129 | 130 | $filters = []; |
| 130 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
| 131 | - if ($schema->hasFilter($name)) { |
|
| 131 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) |
|
| 132 | + { |
|
| 133 | + if ($schema->hasFilter($name)) |
|
| 134 | + { |
|
| 132 | 135 | $filter = $schema->getFilter($name)->withValue($value); |
| 133 | 136 | |
| 134 | - if ($filter !== null) { |
|
| 137 | + if ($filter !== null) |
|
| 138 | + { |
|
| 135 | 139 | $filters[$name] = $filter; |
| 136 | 140 | $values[$name] = $filter->getValue(); |
| 137 | 141 | } |
| 138 | 142 | } |
| 139 | 143 | } |
| 140 | 144 | |
| 141 | - foreach ($schema->wrapFilters($filters) as $filter) { |
|
| 145 | + foreach ($schema->wrapFilters($filters) as $filter) |
|
| 146 | + { |
|
| 142 | 147 | $source = $this->compiler->compile($source, $filter); |
| 143 | 148 | } |
| 144 | 149 | |
@@ -147,7 +152,8 @@ discard block |
||
| 147 | 152 | |
| 148 | 153 | protected function applyCounter(GridInterface $view, $source, GridSchema $schema): array |
| 149 | 154 | { |
| 150 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
| 155 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) |
|
| 156 | + { |
|
| 151 | 157 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
| 152 | 158 | } |
| 153 | 159 | |
@@ -165,11 +171,14 @@ discard block |
||
| 165 | 171 | protected function getSorters($source, GridSchema $schema): array |
| 166 | 172 | { |
| 167 | 173 | $sorters = []; |
| 168 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
| 169 | - if ($schema->hasSorter($name)) { |
|
| 174 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) |
|
| 175 | + { |
|
| 176 | + if ($schema->hasSorter($name)) |
|
| 177 | + { |
|
| 170 | 178 | $sorter = $schema->getSorter($name)->withDirection($value); |
| 171 | 179 | |
| 172 | - if ($sorter !== null) { |
|
| 180 | + if ($sorter !== null) |
|
| 181 | + { |
|
| 173 | 182 | $source = $this->compiler->compile($source, $sorter); |
| 174 | 183 | $sorters[$name] = $sorter->getValue(); |
| 175 | 184 | } |
@@ -181,7 +190,8 @@ discard block |
||
| 181 | 190 | |
| 182 | 191 | protected function applyPaginator(GridInterface $view, $source, GridSchema $schema): array |
| 183 | 192 | { |
| 184 | - if ($schema->getPaginator() !== null) { |
|
| 193 | + if ($schema->getPaginator() !== null) |
|
| 194 | + { |
|
| 185 | 195 | ['source' => $source, 'paginator' => $paginator] = $this->getPaginator($source, $schema); |
| 186 | 196 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator); |
| 187 | 197 | } |
@@ -192,12 +202,14 @@ discard block |
||
| 192 | 202 | protected function getPaginator($source, GridSchema $schema): array |
| 193 | 203 | { |
| 194 | 204 | $paginator = $schema->getPaginator(); |
| 195 | - if (!$paginator instanceof FilterInterface) { |
|
| 205 | + if (!$paginator instanceof FilterInterface) |
|
| 206 | + { |
|
| 196 | 207 | throw new CompilerException('Paginator can not be null'); |
| 197 | 208 | } |
| 198 | 209 | |
| 199 | 210 | $withValue = $paginator->withValue($this->getOption(static::KEY_PAGINATE)); |
| 200 | - if ($withValue === null) { |
|
| 211 | + if ($withValue === null) |
|
| 212 | + { |
|
| 201 | 213 | throw new CompilerException('Paginator can not be null'); |
| 202 | 214 | } |
| 203 | 215 | |
@@ -216,7 +228,8 @@ discard block |
||
| 216 | 228 | protected function getOptionArray(string $option): array |
| 217 | 229 | { |
| 218 | 230 | $result = $this->getOption($option); |
| 219 | - if (!is_array($result)) { |
|
| 231 | + if (!is_array($result)) |
|
| 232 | + { |
|
| 220 | 233 | return []; |
| 221 | 234 | } |
| 222 | 235 | |
@@ -231,7 +244,8 @@ discard block |
||
| 231 | 244 | */ |
| 232 | 245 | protected function getOption(string $option) |
| 233 | 246 | { |
| 234 | - if ($this->input->hasValue($option)) { |
|
| 247 | + if ($this->input->hasValue($option)) |
|
| 248 | + { |
|
| 235 | 249 | return $this->input->getValue($option); |
| 236 | 250 | } |
| 237 | 251 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function addWrappedFilters(callable $wrapper, string ...$filters): void |
| 42 | 42 | { |
| 43 | - foreach ($filters as $filter) { |
|
| 44 | - if (isset($this->wrappedFilters[$filter])) { |
|
| 43 | + foreach ($filters as $filter){ |
|
| 44 | + if (isset($this->wrappedFilters[$filter])){ |
|
| 45 | 45 | throw new SchemaException("Filter `$filter` is already wrapped"); |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | public function wrapFilters(array $input): array |
| 54 | 54 | { |
| 55 | 55 | $output = []; |
| 56 | - foreach ($this->wrappers as $wrapper) { |
|
| 56 | + foreach ($this->wrappers as $wrapper){ |
|
| 57 | 57 | $output[] = $wrapper['wrapper'](...$this->fetchFilters($input, $wrapper['filters'])); |
| 58 | - foreach ($input as $name => $filter) { |
|
| 59 | - if (!in_array($name, $wrapper['filters'], true)) { |
|
| 58 | + foreach ($input as $name => $filter){ |
|
| 59 | + if (!in_array($name, $wrapper['filters'], true)){ |
|
| 60 | 60 | $output[] = $filter; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function addFilter(string $name, FilterInterface $filter): void |
| 76 | 76 | { |
| 77 | - if ($this->hasFilter($name)) { |
|
| 77 | + if ($this->hasFilter($name)){ |
|
| 78 | 78 | throw new SchemaException("Filter `$name` is already defined"); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function getFilter(string $name): FilterInterface |
| 101 | 101 | { |
| 102 | - if (!$this->hasFilter($name)) { |
|
| 102 | + if (!$this->hasFilter($name)){ |
|
| 103 | 103 | throw new SchemaException("No such filter `$name`"); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function addSorter(string $name, SorterInterface $sorter): void |
| 125 | 125 | { |
| 126 | - if ($this->hasSorter($name)) { |
|
| 126 | + if ($this->hasSorter($name)){ |
|
| 127 | 127 | throw new SchemaException("Sorter `$name` is already defined"); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function getSorter(string $name): SorterInterface |
| 150 | 150 | { |
| 151 | - if (!$this->hasSorter($name)) { |
|
| 151 | + if (!$this->hasSorter($name)){ |
|
| 152 | 152 | throw new SchemaException("No such sorter `$name`"); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | private function fetchFilters(array $filters, array $names): array |
| 187 | 187 | { |
| 188 | 188 | $output = []; |
| 189 | - foreach ($names as $name) { |
|
| 189 | + foreach ($names as $name){ |
|
| 190 | 190 | $output[] = $filters[$name] ?? new NullFilter(); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -40,8 +40,10 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function addWrappedFilters(callable $wrapper, string ...$filters): void |
| 42 | 42 | { |
| 43 | - foreach ($filters as $filter) { |
|
| 44 | - if (isset($this->wrappedFilters[$filter])) { |
|
| 43 | + foreach ($filters as $filter) |
|
| 44 | + { |
|
| 45 | + if (isset($this->wrappedFilters[$filter])) |
|
| 46 | + { |
|
| 45 | 47 | throw new SchemaException("Filter `$filter` is already wrapped"); |
| 46 | 48 | } |
| 47 | 49 | } |
@@ -53,10 +55,13 @@ discard block |
||
| 53 | 55 | public function wrapFilters(array $input): array |
| 54 | 56 | { |
| 55 | 57 | $output = []; |
| 56 | - foreach ($this->wrappers as $wrapper) { |
|
| 58 | + foreach ($this->wrappers as $wrapper) |
|
| 59 | + { |
|
| 57 | 60 | $output[] = $wrapper['wrapper'](...$this->fetchFilters($input, $wrapper['filters'])); |
| 58 | - foreach ($input as $name => $filter) { |
|
| 59 | - if (!in_array($name, $wrapper['filters'], true)) { |
|
| 61 | + foreach ($input as $name => $filter) |
|
| 62 | + { |
|
| 63 | + if (!in_array($name, $wrapper['filters'], true)) |
|
| 64 | + { |
|
| 60 | 65 | $output[] = $filter; |
| 61 | 66 | } |
| 62 | 67 | } |
@@ -74,7 +79,8 @@ discard block |
||
| 74 | 79 | */ |
| 75 | 80 | public function addFilter(string $name, FilterInterface $filter): void |
| 76 | 81 | { |
| 77 | - if ($this->hasFilter($name)) { |
|
| 82 | + if ($this->hasFilter($name)) |
|
| 83 | + { |
|
| 78 | 84 | throw new SchemaException("Filter `$name` is already defined"); |
| 79 | 85 | } |
| 80 | 86 | |
@@ -99,7 +105,8 @@ discard block |
||
| 99 | 105 | */ |
| 100 | 106 | public function getFilter(string $name): FilterInterface |
| 101 | 107 | { |
| 102 | - if (!$this->hasFilter($name)) { |
|
| 108 | + if (!$this->hasFilter($name)) |
|
| 109 | + { |
|
| 103 | 110 | throw new SchemaException("No such filter `$name`"); |
| 104 | 111 | } |
| 105 | 112 | |
@@ -123,7 +130,8 @@ discard block |
||
| 123 | 130 | */ |
| 124 | 131 | public function addSorter(string $name, SorterInterface $sorter): void |
| 125 | 132 | { |
| 126 | - if ($this->hasSorter($name)) { |
|
| 133 | + if ($this->hasSorter($name)) |
|
| 134 | + { |
|
| 127 | 135 | throw new SchemaException("Sorter `$name` is already defined"); |
| 128 | 136 | } |
| 129 | 137 | |
@@ -148,7 +156,8 @@ discard block |
||
| 148 | 156 | */ |
| 149 | 157 | public function getSorter(string $name): SorterInterface |
| 150 | 158 | { |
| 151 | - if (!$this->hasSorter($name)) { |
|
| 159 | + if (!$this->hasSorter($name)) |
|
| 160 | + { |
|
| 152 | 161 | throw new SchemaException("No such sorter `$name`"); |
| 153 | 162 | } |
| 154 | 163 | |
@@ -186,7 +195,8 @@ discard block |
||
| 186 | 195 | private function fetchFilters(array $filters, array $names): array |
| 187 | 196 | { |
| 188 | 197 | $output = []; |
| 189 | - foreach ($names as $name) { |
|
| 198 | + foreach ($names as $name) |
|
| 199 | + { |
|
| 190 | 200 | $output[] = $filters[$name] ?? new NullFilter(); |
| 191 | 201 | } |
| 192 | 202 | |