Passed
Pull Request — master (#368)
by Valentin
04:22
created
src/DataGrid/src/GridFactory.php 1 patch
Braces   +26 added lines, -13 removed lines patch added patch discarded remove patch
@@ -116,7 +116,8 @@  discard block
 block discarded – undo
116 116
         ['view' => $view, 'source' => $source] = $this->applySorters($view, $source, $schema);
117 117
         ['view' => $view, 'source' => $source] = $this->applyPaginator($view, $source, $schema);
118 118
 
119
-        if (!is_iterable($source)) {
119
+        if (!is_iterable($source))
120
+        {
120 121
             throw new GridViewException('GridView expects the source to be iterable after all.');
121 122
         }
122 123
 
@@ -134,11 +135,14 @@  discard block
 block discarded – undo
134 135
     protected function getFilters($source, GridSchema $schema): array
135 136
     {
136 137
         $filters = [];
137
-        foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) {
138
-            if ($schema->hasFilter($name)) {
138
+        foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value)
139
+        {
140
+            if ($schema->hasFilter($name))
141
+            {
139 142
                 $filter = $schema->getFilter($name)->withValue($value);
140 143
 
141
-                if ($filter !== null) {
144
+                if ($filter !== null)
145
+                {
142 146
                     $source = $this->compiler->compile($source, $filter);
143 147
                     $filters[$name] = $filter->getValue();
144 148
                 }
@@ -150,7 +154,8 @@  discard block
 block discarded – undo
150 154
 
151 155
     protected function applyCounter(GridInterface $view, $source, GridSchema $schema): array
152 156
     {
153
-        if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) {
157
+        if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT))
158
+        {
154 159
             $view = $view->withOption(GridInterface::COUNT, ($this->count)($source));
155 160
         }
156 161
 
@@ -168,11 +173,14 @@  discard block
 block discarded – undo
168 173
     protected function getSorters($source, GridSchema $schema): array
169 174
     {
170 175
         $sorters = [];
171
-        foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) {
172
-            if ($schema->hasSorter($name)) {
176
+        foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value)
177
+        {
178
+            if ($schema->hasSorter($name))
179
+            {
173 180
                 $sorter = $schema->getSorter($name)->withDirection($value);
174 181
 
175
-                if ($sorter !== null) {
182
+                if ($sorter !== null)
183
+                {
176 184
                     $source = $this->compiler->compile($source, $sorter);
177 185
                     $sorters[$name] = $sorter->getValue();
178 186
                 }
@@ -184,7 +192,8 @@  discard block
 block discarded – undo
184 192
 
185 193
     protected function applyPaginator(GridInterface $view, $source, GridSchema $schema): array
186 194
     {
187
-        if ($schema->getPaginator() !== null) {
195
+        if ($schema->getPaginator() !== null)
196
+        {
188 197
             ['source' => $source, 'paginator' => $paginator] = $this->getPaginator($source, $schema);
189 198
             $view = $view->withOption(GridInterface::PAGINATOR, $paginator);
190 199
         }
@@ -195,12 +204,14 @@  discard block
 block discarded – undo
195 204
     protected function getPaginator($source, GridSchema $schema): array
196 205
     {
197 206
         $paginator = $schema->getPaginator();
198
-        if (!$paginator instanceof FilterInterface) {
207
+        if (!$paginator instanceof FilterInterface)
208
+        {
199 209
             throw new CompilerException('Paginator can not be null');
200 210
         }
201 211
 
202 212
         $withValue = $paginator->withValue($this->getOption(static::KEY_PAGINATE));
203
-        if ($withValue === null) {
213
+        if ($withValue === null)
214
+        {
204 215
             throw new CompilerException('Paginator can not be null');
205 216
         }
206 217
 
@@ -219,7 +230,8 @@  discard block
 block discarded – undo
219 230
     protected function getOptionArray(string $option): array
220 231
     {
221 232
         $result = $this->getOption($option);
222
-        if (!is_array($result)) {
233
+        if (!is_array($result))
234
+        {
223 235
             return [];
224 236
         }
225 237
 
@@ -234,7 +246,8 @@  discard block
 block discarded – undo
234 246
      */
235 247
     protected function getOption(string $option)
236 248
     {
237
-        if ($this->mapper->hasOption($option)) {
249
+        if ($this->mapper->hasOption($option))
250
+        {
238 251
             return $this->mapper->getOption($option);
239 252
         }
240 253
 
Please login to merge, or discard this patch.
src/DataGridBridge/src/Interceptor/GridInterceptor.php 1 patch
Braces   +33 added lines, -16 removed lines patch added patch discarded remove patch
@@ -74,14 +74,17 @@  discard block
 block discarded – undo
74 74
     {
75 75
         $result = $core->callAction($controller, $action, $parameters);
76 76
 
77
-        if (is_iterable($result)) {
77
+        if (is_iterable($result))
78
+        {
78 79
             $schema = $this->getSchema($controller, $action);
79
-            if ($schema !== null) {
80
+            if ($schema !== null)
81
+            {
80 82
                 $grid = $this->makeFactory($schema)
81 83
                     ->withDefaults($schema['defaults'])
82 84
                     ->create($result, $schema['grid']);
83 85
 
84
-                if ($schema['view'] !== null) {
86
+                if ($schema['view'] !== null)
87
+                {
85 88
                     $grid = $grid->withView($schema['view']);
86 89
                 }
87 90
 
@@ -101,14 +104,18 @@  discard block
 block discarded – undo
101 104
     private function getSchema(string $controller, string $action): ?array
102 105
     {
103 106
         $key = sprintf('%s:%s', $controller, $action);
104
-        if (array_key_exists($key, $this->cache)) {
107
+        if (array_key_exists($key, $this->cache))
108
+        {
105 109
             return $this->cache[$key];
106 110
         }
107 111
 
108 112
         $this->cache[$key] = null;
109
-        try {
113
+        try
114
+        {
110 115
             $method = new \ReflectionMethod($controller, $action);
111
-        } catch (\ReflectionException $e) {
116
+        }
117
+        catch (\ReflectionException $e)
118
+        {
112 119
             return null;
113 120
         }
114 121
 
@@ -116,7 +123,8 @@  discard block
 block discarded – undo
116 123
 
117 124
         /** @var DataGrid $dataGrid */
118 125
         $dataGrid = $reader->getMethodAnnotation($method, DataGrid::class);
119
-        if ($dataGrid === null) {
126
+        if ($dataGrid === null)
127
+        {
120 128
             return null;
121 129
         }
122 130
 
@@ -139,23 +147,28 @@  discard block
 block discarded – undo
139 147
             'mapping'  => $dataGrid->mapping,
140 148
         ];
141 149
 
142
-        if (is_string($schema['view'])) {
150
+        if (is_string($schema['view']))
151
+        {
143 152
             $schema['view'] = $this->container->get($schema['view']);
144 153
         }
145 154
 
146
-        if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) {
155
+        if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults'))
156
+        {
147 157
             $schema['defaults'] = $schema['grid']->getDefaults();
148 158
         }
149 159
 
150
-        if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) {
160
+        if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions'))
161
+        {
151 162
             $schema['options'] = $schema['grid']->getOptions();
152 163
         }
153 164
 
154
-        if ($schema['view'] === null && is_callable($schema['grid'])) {
165
+        if ($schema['view'] === null && is_callable($schema['grid']))
166
+        {
155 167
             $schema['view'] = $schema['grid'];
156 168
         }
157 169
 
158
-        if ($schema['mapping'] === [] && method_exists($schema['grid'], 'getMapping')) {
170
+        if ($schema['mapping'] === [] && method_exists($schema['grid'], 'getMapping'))
171
+        {
159 172
             $schema['mapping'] = $schema['grid']->getMapping();
160 173
         }
161 174
 
@@ -164,16 +177,20 @@  discard block
 block discarded – undo
164 177
 
165 178
     private function makeFactory(array $schema): GridFactoryInterface
166 179
     {
167
-        if (!empty($schema['factory']) && $this->container->has($schema['factory'])) {
180
+        if (!empty($schema['factory']) && $this->container->has($schema['factory']))
181
+        {
168 182
             $factory = $this->container->get($schema['factory']);
169
-            if ($factory instanceof GridFactoryInterface) {
183
+            if ($factory instanceof GridFactoryInterface)
184
+            {
170 185
                 return $factory;
171 186
             }
172 187
         }
173 188
 
174
-        if (!empty($schema['mapping']) && !empty($schema['mapper']) && $this->container->has($schema['mapper'])) {
189
+        if (!empty($schema['mapping']) && !empty($schema['mapper']) && $this->container->has($schema['mapper']))
190
+        {
175 191
             $mapper = $this->factory->make($schema['mapper'], ['mapping' => $schema['mapping']]);
176
-            if ($mapper instanceof InputMapperInterface) {
192
+            if ($mapper instanceof InputMapperInterface)
193
+            {
177 194
                 return $this->gridFactory->withMapper($mapper);
178 195
             }
179 196
         }
Please login to merge, or discard this patch.
src/DataGrid/src/InputMapper.php 1 patch
Braces   +24 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,15 +32,18 @@  discard block
 block discarded – undo
32 32
 
33 33
     public function hasOption(string $option): bool
34 34
     {
35
-        if (!isset($this->mapped[$option])) {
35
+        if (!isset($this->mapped[$option]))
36
+        {
36 37
             return $this->input->hasValue($option);
37 38
         }
38 39
 
39 40
         $mappedOptions = $this->mapped[$option];
40
-        foreach ($mappedOptions as $mappedOption) {
41
+        foreach ($mappedOptions as $mappedOption)
42
+        {
41 43
             $paths = $mappedOption[0];
42 44
             $firstPath = array_shift($paths);
43
-            if ($this->input->hasValue($firstPath)) {
45
+            if ($this->input->hasValue($firstPath))
46
+            {
44 47
                 return true;
45 48
             }
46 49
         }
@@ -50,33 +53,40 @@  discard block
 block discarded – undo
50 53
 
51 54
     public function getOption(string $option, $default = null)
52 55
     {
53
-        if (!isset($this->mapped[$option])) {
56
+        if (!isset($this->mapped[$option]))
57
+        {
54 58
             return $this->input->getValue($option, $default);
55 59
         }
56 60
 
57 61
         $mappedOptions = $this->mapped[$option];
58 62
         $output = [];
59
-        foreach ($mappedOptions as $mappedOption) {
63
+        foreach ($mappedOptions as $mappedOption)
64
+        {
60 65
             [$paths, $to] = $mappedOption;
61 66
             $firstPath = array_shift($paths);
62
-            if (!$this->input->hasValue($firstPath)) {
67
+            if (!$this->input->hasValue($firstPath))
68
+            {
63 69
                 continue;
64 70
             }
65 71
 
66 72
             $data = $this->input->getValue($firstPath);
67
-            if (!empty($paths) && !is_array($data)) {
73
+            if (!empty($paths) && !is_array($data))
74
+            {
68 75
                 continue;
69 76
             }
70 77
 
71
-            foreach ($paths as $path) {
72
-                if (!is_array($data) || !isset($data[$path])) {
78
+            foreach ($paths as $path)
79
+            {
80
+                if (!is_array($data) || !isset($data[$path]))
81
+                {
73 82
                     continue 2;
74 83
                 }
75 84
                 $data = $data[$path];
76 85
             }
77 86
 
78 87
             $result = $data;
79
-            foreach ($to as $path) {
88
+            foreach ($to as $path)
89
+            {
80 90
                 $result = [$path => $result];
81 91
             }
82 92
 
@@ -88,10 +98,12 @@  discard block
 block discarded – undo
88 98
 
89 99
     protected function map(): void
90 100
     {
91
-        foreach ($this->mapping as $from => $to) {
101
+        foreach ($this->mapping as $from => $to)
102
+        {
92 103
             $to = explode('.', $to);
93 104
             $option = array_shift($to);
94
-            if (!isset($this->mapped[$option])) {
105
+            if (!isset($this->mapped[$option]))
106
+            {
95 107
                 $this->mapped[$option] = [];
96 108
             }
97 109
             $this->mapped[$option][] = [explode('.', $from), array_reverse($to)];
Please login to merge, or discard this patch.