@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | public function hasOption(string $option): bool |
33 | 33 | { |
34 | 34 | $mapped = $this->map($option); |
35 | - if (!isset($mapped[$option])) { |
|
35 | + if (!isset($mapped[$option])){ |
|
36 | 36 | return $this->input->hasValue($option); |
37 | 37 | } |
38 | 38 | |
39 | 39 | $paths = (array)$mapped[$option][0]; |
40 | 40 | |
41 | 41 | $firstPath = array_shift($paths); |
42 | - if (!$this->input->hasValue($firstPath)) { |
|
42 | + if (!$this->input->hasValue($firstPath)){ |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | |
46 | - if (empty($paths)) { |
|
46 | + if (empty($paths)){ |
|
47 | 47 | return true; |
48 | 48 | } |
49 | 49 | |
50 | 50 | $data = $this->input->getValue($firstPath); |
51 | - foreach ($paths as $path) { |
|
52 | - if (!is_array($data)) { |
|
51 | + foreach ($paths as $path){ |
|
52 | + if (!is_array($data)){ |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | |
56 | - if (!isset($data[$path])) { |
|
56 | + if (!isset($data[$path])){ |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
@@ -67,37 +67,37 @@ discard block |
||
67 | 67 | { |
68 | 68 | $mappedOptions = $this->map($option); |
69 | 69 | |
70 | - if (!isset($mappedOptions)) { |
|
70 | + if (!isset($mappedOptions)){ |
|
71 | 71 | return $this->input->getValue($option); |
72 | 72 | } |
73 | 73 | |
74 | 74 | $output = []; |
75 | - foreach ($mappedOptions as $mappedOption) { |
|
75 | + foreach ($mappedOptions as $mappedOption){ |
|
76 | 76 | $paths = (array)$mappedOption[0]; |
77 | 77 | |
78 | 78 | $firstPath = array_shift($paths); |
79 | - if (!$this->input->getValue($firstPath)) { |
|
79 | + if (!$this->input->getValue($firstPath)){ |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | |
83 | 83 | $data = $this->input->getValue($firstPath); |
84 | 84 | $unmappedData = $data; |
85 | - if (!empty($paths) && is_array($unmappedData)) { |
|
85 | + if (!empty($paths) && is_array($unmappedData)){ |
|
86 | 86 | dump(compact('unmappedData', 'paths')); |
87 | 87 | unset($unmappedData[$paths[0]]); |
88 | 88 | dump(compact('unmappedData')); |
89 | 89 | } |
90 | 90 | |
91 | - foreach ($paths as $path) { |
|
91 | + foreach ($paths as $path){ |
|
92 | 92 | $data = $data[$path]; |
93 | 93 | } |
94 | 94 | |
95 | 95 | $result = $data; |
96 | - foreach ((array)$mappedOption[1] as $path) { |
|
96 | + foreach ((array)$mappedOption[1] as $path){ |
|
97 | 97 | $result = [$path => $result]; |
98 | 98 | } |
99 | 99 | $output[] = $result; |
100 | - if (is_array($unmappedData)) { |
|
100 | + if (is_array($unmappedData)){ |
|
101 | 101 | $output[] = $unmappedData; |
102 | 102 | } |
103 | 103 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | |
108 | 108 | protected function map(string $option): array |
109 | 109 | { |
110 | - if (isset($this->mapped[$option])) { |
|
110 | + if (isset($this->mapped[$option])){ |
|
111 | 111 | return $this->mapped[$option]; |
112 | 112 | } |
113 | 113 | |
114 | 114 | $result = []; |
115 | - foreach ($this->mapping as $from => $to) { |
|
115 | + foreach ($this->mapping as $from => $to){ |
|
116 | 116 | $to = explode('.', $to); |
117 | - if (isset($to[0]) && $to[0] === $option) { |
|
117 | + if (isset($to[0]) && $to[0] === $option){ |
|
118 | 118 | array_shift($to); |
119 | 119 | $result[] = [explode('.', $from), array_reverse($to)]; |
120 | 120 | } |
@@ -32,28 +32,34 @@ discard block |
||
32 | 32 | public function hasOption(string $option): bool |
33 | 33 | { |
34 | 34 | $mapped = $this->map($option); |
35 | - if (!isset($mapped[$option])) { |
|
35 | + if (!isset($mapped[$option])) |
|
36 | + { |
|
36 | 37 | return $this->input->hasValue($option); |
37 | 38 | } |
38 | 39 | |
39 | 40 | $paths = (array)$mapped[$option][0]; |
40 | 41 | |
41 | 42 | $firstPath = array_shift($paths); |
42 | - if (!$this->input->hasValue($firstPath)) { |
|
43 | + if (!$this->input->hasValue($firstPath)) |
|
44 | + { |
|
43 | 45 | return false; |
44 | 46 | } |
45 | 47 | |
46 | - if (empty($paths)) { |
|
48 | + if (empty($paths)) |
|
49 | + { |
|
47 | 50 | return true; |
48 | 51 | } |
49 | 52 | |
50 | 53 | $data = $this->input->getValue($firstPath); |
51 | - foreach ($paths as $path) { |
|
52 | - if (!is_array($data)) { |
|
54 | + foreach ($paths as $path) |
|
55 | + { |
|
56 | + if (!is_array($data)) |
|
57 | + { |
|
53 | 58 | return false; |
54 | 59 | } |
55 | 60 | |
56 | - if (!isset($data[$path])) { |
|
61 | + if (!isset($data[$path])) |
|
62 | + { |
|
57 | 63 | return false; |
58 | 64 | } |
59 | 65 | |
@@ -67,37 +73,44 @@ discard block |
||
67 | 73 | { |
68 | 74 | $mappedOptions = $this->map($option); |
69 | 75 | |
70 | - if (!isset($mappedOptions)) { |
|
76 | + if (!isset($mappedOptions)) |
|
77 | + { |
|
71 | 78 | return $this->input->getValue($option); |
72 | 79 | } |
73 | 80 | |
74 | 81 | $output = []; |
75 | - foreach ($mappedOptions as $mappedOption) { |
|
82 | + foreach ($mappedOptions as $mappedOption) |
|
83 | + { |
|
76 | 84 | $paths = (array)$mappedOption[0]; |
77 | 85 | |
78 | 86 | $firstPath = array_shift($paths); |
79 | - if (!$this->input->getValue($firstPath)) { |
|
87 | + if (!$this->input->getValue($firstPath)) |
|
88 | + { |
|
80 | 89 | return false; |
81 | 90 | } |
82 | 91 | |
83 | 92 | $data = $this->input->getValue($firstPath); |
84 | 93 | $unmappedData = $data; |
85 | - if (!empty($paths) && is_array($unmappedData)) { |
|
94 | + if (!empty($paths) && is_array($unmappedData)) |
|
95 | + { |
|
86 | 96 | dump(compact('unmappedData', 'paths')); |
87 | 97 | unset($unmappedData[$paths[0]]); |
88 | 98 | dump(compact('unmappedData')); |
89 | 99 | } |
90 | 100 | |
91 | - foreach ($paths as $path) { |
|
101 | + foreach ($paths as $path) |
|
102 | + { |
|
92 | 103 | $data = $data[$path]; |
93 | 104 | } |
94 | 105 | |
95 | 106 | $result = $data; |
96 | - foreach ((array)$mappedOption[1] as $path) { |
|
107 | + foreach ((array)$mappedOption[1] as $path) |
|
108 | + { |
|
97 | 109 | $result = [$path => $result]; |
98 | 110 | } |
99 | 111 | $output[] = $result; |
100 | - if (is_array($unmappedData)) { |
|
112 | + if (is_array($unmappedData)) |
|
113 | + { |
|
101 | 114 | $output[] = $unmappedData; |
102 | 115 | } |
103 | 116 | } |
@@ -107,14 +120,17 @@ discard block |
||
107 | 120 | |
108 | 121 | protected function map(string $option): array |
109 | 122 | { |
110 | - if (isset($this->mapped[$option])) { |
|
123 | + if (isset($this->mapped[$option])) |
|
124 | + { |
|
111 | 125 | return $this->mapped[$option]; |
112 | 126 | } |
113 | 127 | |
114 | 128 | $result = []; |
115 | - foreach ($this->mapping as $from => $to) { |
|
129 | + foreach ($this->mapping as $from => $to) |
|
130 | + { |
|
116 | 131 | $to = explode('.', $to); |
117 | - if (isset($to[0]) && $to[0] === $option) { |
|
132 | + if (isset($to[0]) && $to[0] === $option) |
|
133 | + { |
|
118 | 134 | array_shift($to); |
119 | 135 | $result[] = [explode('.', $from), array_reverse($to)]; |
120 | 136 | } |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | $view = clone $this->view; |
112 | 112 | |
113 | 113 | $filters = []; |
114 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
115 | - if ($schema->hasFilter($name)) { |
|
114 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value){ |
|
115 | + if ($schema->hasFilter($name)){ |
|
116 | 116 | $filter = $schema->getFilter($name)->withValue($value); |
117 | 117 | |
118 | - if ($filter !== null) { |
|
118 | + if ($filter !== null){ |
|
119 | 119 | $source = $this->compiler->compile($source, $filter); |
120 | 120 | $filters[$name] = $filter->getValue(); |
121 | 121 | } |
@@ -123,16 +123,16 @@ discard block |
||
123 | 123 | } |
124 | 124 | $view = $view->withOption(GridInterface::FILTERS, $filters); |
125 | 125 | |
126 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
126 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)){ |
|
127 | 127 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
128 | 128 | } |
129 | 129 | |
130 | 130 | $sorters = []; |
131 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
132 | - if ($schema->hasSorter($name)) { |
|
131 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value){ |
|
132 | + if ($schema->hasSorter($name)){ |
|
133 | 133 | $sorter = $schema->getSorter($name)->withDirection($value); |
134 | 134 | |
135 | - if ($sorter !== null) { |
|
135 | + if ($sorter !== null){ |
|
136 | 136 | $source = $this->compiler->compile($source, $sorter); |
137 | 137 | $sorters[$name] = $sorter->getValue(); |
138 | 138 | } |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | } |
141 | 141 | $view = $view->withOption(GridInterface::SORTERS, $sorters); |
142 | 142 | |
143 | - if ($schema->getPaginator() !== null) { |
|
143 | + if ($schema->getPaginator() !== null){ |
|
144 | 144 | $paginator = $schema->getPaginator()->withValue($this->getOption(static::KEY_PAGINATE)); |
145 | - if ($paginator === null) { |
|
145 | + if ($paginator === null){ |
|
146 | 146 | throw new CompilerException('The paginator can not be null'); |
147 | 147 | } |
148 | 148 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator->getValue()); |
151 | 151 | } |
152 | 152 | |
153 | - if (!is_iterable($source)) { |
|
153 | + if (!is_iterable($source)){ |
|
154 | 154 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
155 | 155 | } |
156 | 156 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | private function getOptionArray(string $option): array |
167 | 167 | { |
168 | 168 | $result = $this->getOption($option); |
169 | - if (!is_array($result)) { |
|
169 | + if (!is_array($result)){ |
|
170 | 170 | return []; |
171 | 171 | } |
172 | 172 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | private function getOption(string $option) |
183 | 183 | { |
184 | - if ($this->mapper->hasOption($option)) { |
|
184 | + if ($this->mapper->hasOption($option)){ |
|
185 | 185 | return $this->mapper->getOption($option); |
186 | 186 | } |
187 | 187 |
@@ -111,11 +111,14 @@ discard block |
||
111 | 111 | $view = clone $this->view; |
112 | 112 | |
113 | 113 | $filters = []; |
114 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
115 | - if ($schema->hasFilter($name)) { |
|
114 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) |
|
115 | + { |
|
116 | + if ($schema->hasFilter($name)) |
|
117 | + { |
|
116 | 118 | $filter = $schema->getFilter($name)->withValue($value); |
117 | 119 | |
118 | - if ($filter !== null) { |
|
120 | + if ($filter !== null) |
|
121 | + { |
|
119 | 122 | $source = $this->compiler->compile($source, $filter); |
120 | 123 | $filters[$name] = $filter->getValue(); |
121 | 124 | } |
@@ -123,16 +126,20 @@ discard block |
||
123 | 126 | } |
124 | 127 | $view = $view->withOption(GridInterface::FILTERS, $filters); |
125 | 128 | |
126 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
129 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) |
|
130 | + { |
|
127 | 131 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
128 | 132 | } |
129 | 133 | |
130 | 134 | $sorters = []; |
131 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
132 | - if ($schema->hasSorter($name)) { |
|
135 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) |
|
136 | + { |
|
137 | + if ($schema->hasSorter($name)) |
|
138 | + { |
|
133 | 139 | $sorter = $schema->getSorter($name)->withDirection($value); |
134 | 140 | |
135 | - if ($sorter !== null) { |
|
141 | + if ($sorter !== null) |
|
142 | + { |
|
136 | 143 | $source = $this->compiler->compile($source, $sorter); |
137 | 144 | $sorters[$name] = $sorter->getValue(); |
138 | 145 | } |
@@ -140,9 +147,11 @@ discard block |
||
140 | 147 | } |
141 | 148 | $view = $view->withOption(GridInterface::SORTERS, $sorters); |
142 | 149 | |
143 | - if ($schema->getPaginator() !== null) { |
|
150 | + if ($schema->getPaginator() !== null) |
|
151 | + { |
|
144 | 152 | $paginator = $schema->getPaginator()->withValue($this->getOption(static::KEY_PAGINATE)); |
145 | - if ($paginator === null) { |
|
153 | + if ($paginator === null) |
|
154 | + { |
|
146 | 155 | throw new CompilerException('The paginator can not be null'); |
147 | 156 | } |
148 | 157 | |
@@ -150,7 +159,8 @@ discard block |
||
150 | 159 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator->getValue()); |
151 | 160 | } |
152 | 161 | |
153 | - if (!is_iterable($source)) { |
|
162 | + if (!is_iterable($source)) |
|
163 | + { |
|
154 | 164 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
155 | 165 | } |
156 | 166 | |
@@ -166,7 +176,8 @@ discard block |
||
166 | 176 | private function getOptionArray(string $option): array |
167 | 177 | { |
168 | 178 | $result = $this->getOption($option); |
169 | - if (!is_array($result)) { |
|
179 | + if (!is_array($result)) |
|
180 | + { |
|
170 | 181 | return []; |
171 | 182 | } |
172 | 183 | |
@@ -181,7 +192,8 @@ discard block |
||
181 | 192 | */ |
182 | 193 | private function getOption(string $option) |
183 | 194 | { |
184 | - if ($this->mapper->hasOption($option)) { |
|
195 | + if ($this->mapper->hasOption($option)) |
|
196 | + { |
|
185 | 197 | return $this->mapper->getOption($option); |
186 | 198 | } |
187 | 199 |