@@ -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,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 | |
@@ -41,7 +41,8 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function wrapFilters(array $input): array |
| 43 | 43 | { |
| 44 | - if (!$this->wrapper) { |
|
| 44 | + if (!$this->wrapper) |
|
| 45 | + { |
|
| 45 | 46 | return $input; |
| 46 | 47 | } |
| 47 | 48 | |
@@ -58,7 +59,8 @@ discard block |
||
| 58 | 59 | */ |
| 59 | 60 | public function addFilter(string $name, FilterInterface $filter): void |
| 60 | 61 | { |
| 61 | - if ($this->hasFilter($name)) { |
|
| 62 | + if ($this->hasFilter($name)) |
|
| 63 | + { |
|
| 62 | 64 | throw new SchemaException("Filter `$name` is already defined"); |
| 63 | 65 | } |
| 64 | 66 | |
@@ -83,7 +85,8 @@ discard block |
||
| 83 | 85 | */ |
| 84 | 86 | public function getFilter(string $name): FilterInterface |
| 85 | 87 | { |
| 86 | - if (!$this->hasFilter($name)) { |
|
| 88 | + if (!$this->hasFilter($name)) |
|
| 89 | + { |
|
| 87 | 90 | throw new SchemaException("No such filter `$name`"); |
| 88 | 91 | } |
| 89 | 92 | |
@@ -107,7 +110,8 @@ discard block |
||
| 107 | 110 | */ |
| 108 | 111 | public function addSorter(string $name, SorterInterface $sorter): void |
| 109 | 112 | { |
| 110 | - if ($this->hasSorter($name)) { |
|
| 113 | + if ($this->hasSorter($name)) |
|
| 114 | + { |
|
| 111 | 115 | throw new SchemaException("Sorter `$name` is already defined"); |
| 112 | 116 | } |
| 113 | 117 | |
@@ -132,7 +136,8 @@ discard block |
||
| 132 | 136 | */ |
| 133 | 137 | public function getSorter(string $name): SorterInterface |
| 134 | 138 | { |
| 135 | - if (!$this->hasSorter($name)) { |
|
| 139 | + if (!$this->hasSorter($name)) |
|
| 140 | + { |
|
| 136 | 141 | throw new SchemaException("No such sorter `$name`"); |
| 137 | 142 | } |
| 138 | 143 | |
@@ -240,7 +240,8 @@ discard block |
||
| 240 | 240 | $expected, |
| 241 | 241 | string $expectedException = null |
| 242 | 242 | ): void { |
| 243 | - if ($expectedException !== null) { |
|
| 243 | + if ($expectedException !== null) |
|
| 244 | + { |
|
| 244 | 245 | $this->expectException($expectedException); |
| 245 | 246 | } |
| 246 | 247 | |
@@ -302,7 +303,8 @@ discard block |
||
| 302 | 303 | function (array $filters): array { |
| 303 | 304 | $size = $filters['size'] ?? null; |
| 304 | 305 | $color = $filters['color'] ?? null; |
| 305 | - if ($size && $color) { |
|
| 306 | + if ($size && $color) |
|
| 307 | + { |
|
| 306 | 308 | unset($filters['size'], $filters['color']); |
| 307 | 309 | $filters[] = new Any($size, $color); |
| 308 | 310 | } |
@@ -368,15 +370,18 @@ discard block |
||
| 368 | 370 | private function paginatorInput(int $page = null, int $limit = null): array |
| 369 | 371 | { |
| 370 | 372 | $result = []; |
| 371 | - if ($page === null && $limit === null) { |
|
| 373 | + if ($page === null && $limit === null) |
|
| 374 | + { |
|
| 372 | 375 | return $result; |
| 373 | 376 | } |
| 374 | 377 | |
| 375 | - if ($page !== null) { |
|
| 378 | + if ($page !== null) |
|
| 379 | + { |
|
| 376 | 380 | $result['page'] = $page; |
| 377 | 381 | } |
| 378 | 382 | |
| 379 | - if ($limit !== null) { |
|
| 383 | + if ($limit !== null) |
|
| 384 | + { |
|
| 380 | 385 | $result['limit'] = $limit; |
| 381 | 386 | } |
| 382 | 387 | |