Passed
Pull Request — master (#368)
by Valentin
04:09
created
src/DataGrid/src/GridFactory.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +24 added lines, -12 removed lines patch added patch discarded remove patch
@@ -111,11 +111,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/DataGrid/src/InputMapper.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,15 +32,15 @@  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
             return $this->input->hasValue($option);
37 37
         }
38 38
 
39 39
         $mappedOptions = $this->mapped[$option];
40
-        foreach ($mappedOptions as $mappedOption) {
40
+        foreach ($mappedOptions as $mappedOption){
41 41
             $paths = $mappedOption[0];
42 42
             $firstPath = array_shift($paths);
43
-            if ($this->input->hasValue($firstPath)) {
43
+            if ($this->input->hasValue($firstPath)){
44 44
                 return true;
45 45
             }
46 46
         }
@@ -54,33 +54,33 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function getOption(string $option)
56 56
     {
57
-        if (!isset($this->mapped[$option])) {
57
+        if (!isset($this->mapped[$option])){
58 58
             return $this->input->getValue($option);
59 59
         }
60 60
 
61 61
         $mappedOptions = $this->mapped[$option];
62 62
         $output = [];
63
-        foreach ($mappedOptions as $mappedOption) {
63
+        foreach ($mappedOptions as $mappedOption){
64 64
             [$paths, $to] = $mappedOption;
65 65
             $firstPath = array_shift($paths);
66
-            if (!$this->input->hasValue($firstPath)) {
66
+            if (!$this->input->hasValue($firstPath)){
67 67
                 continue;
68 68
             }
69 69
 
70 70
             $data = $this->input->getValue($firstPath);
71
-            if (!empty($paths) && !is_array($data)) {
71
+            if (!empty($paths) && !is_array($data)){
72 72
                 continue;
73 73
             }
74 74
 
75
-            foreach ($paths as $path) {
76
-                if (!is_array($data) || !isset($data[$path])) {
75
+            foreach ($paths as $path){
76
+                if (!is_array($data) || !isset($data[$path])){
77 77
                     continue 2;
78 78
                 }
79 79
                 $data = $data[$path];
80 80
             }
81 81
 
82 82
             $result = $data;
83
-            foreach ($to as $path) {
83
+            foreach ($to as $path){
84 84
                 $result = [$path => $result];
85 85
             }
86 86
 
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 
93 93
     protected function map(): void
94 94
     {
95
-        foreach ($this->mapping as $from => $to) {
95
+        foreach ($this->mapping as $from => $to){
96 96
             $to = explode('.', $to);
97 97
             $option = array_shift($to);
98
-            if (!isset($this->mapped[$option])) {
98
+            if (!isset($this->mapped[$option])){
99 99
                 $this->mapped[$option] = [];
100 100
             }
101 101
             $this->mapped[$option][] = [explode('.', $from), array_reverse($to)];
Please login to merge, or discard this 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
         }
@@ -54,33 +57,40 @@  discard block
 block discarded – undo
54 57
      */
55 58
     public function getOption(string $option)
56 59
     {
57
-        if (!isset($this->mapped[$option])) {
60
+        if (!isset($this->mapped[$option]))
61
+        {
58 62
             return $this->input->getValue($option);
59 63
         }
60 64
 
61 65
         $mappedOptions = $this->mapped[$option];
62 66
         $output = [];
63
-        foreach ($mappedOptions as $mappedOption) {
67
+        foreach ($mappedOptions as $mappedOption)
68
+        {
64 69
             [$paths, $to] = $mappedOption;
65 70
             $firstPath = array_shift($paths);
66
-            if (!$this->input->hasValue($firstPath)) {
71
+            if (!$this->input->hasValue($firstPath))
72
+            {
67 73
                 continue;
68 74
             }
69 75
 
70 76
             $data = $this->input->getValue($firstPath);
71
-            if (!empty($paths) && !is_array($data)) {
77
+            if (!empty($paths) && !is_array($data))
78
+            {
72 79
                 continue;
73 80
             }
74 81
 
75
-            foreach ($paths as $path) {
76
-                if (!is_array($data) || !isset($data[$path])) {
82
+            foreach ($paths as $path)
83
+            {
84
+                if (!is_array($data) || !isset($data[$path]))
85
+                {
77 86
                     continue 2;
78 87
                 }
79 88
                 $data = $data[$path];
80 89
             }
81 90
 
82 91
             $result = $data;
83
-            foreach ($to as $path) {
92
+            foreach ($to as $path)
93
+            {
84 94
                 $result = [$path => $result];
85 95
             }
86 96
 
@@ -92,10 +102,12 @@  discard block
 block discarded – undo
92 102
 
93 103
     protected function map(): void
94 104
     {
95
-        foreach ($this->mapping as $from => $to) {
105
+        foreach ($this->mapping as $from => $to)
106
+        {
96 107
             $to = explode('.', $to);
97 108
             $option = array_shift($to);
98
-            if (!isset($this->mapped[$option])) {
109
+            if (!isset($this->mapped[$option]))
110
+            {
99 111
                 $this->mapped[$option] = [];
100 112
             }
101 113
             $this->mapped[$option][] = [explode('.', $from), array_reverse($to)];
Please login to merge, or discard this patch.
src/DataGrid/tests/MapperTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
             $mapper->getOption('sort')
80 80
         );
81 81
         $this->assertSame(
82
-            ['byOldestFilter' => false,],
82
+            ['byOldestFilter' => false, ],
83 83
             $mapper->getOption('filter')
84 84
         );
85 85
     }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
             $mapper->getOption('sort')
119 119
         );
120 120
         $this->assertSame(
121
-            ['by' => ['oldest' => false],],
121
+            ['by' => ['oldest' => false], ],
122 122
             $mapper->getOption('filter')
123 123
         );
124 124
     }
Please login to merge, or discard this patch.