Passed
Pull Request — master (#450)
by Kirill
21:41 queued 07:01
created
src/Filters/src/SchemaBuilder.php 1 patch
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -70,18 +70,22 @@  discard block
 block discarded – undo
70 70
     protected function buildMap(ReflectionEntity $filter): array
71 71
     {
72 72
         $schema = $filter->getProperty('schema', true);
73
-        if (empty($schema)) {
73
+        if (empty($schema))
74
+        {
74 75
             throw new SchemaException("Filter `{$filter->getName()}` does not define any schema");
75 76
         }
76 77
 
77 78
         $result = [];
78
-        foreach ($schema as $field => $definition) {
79
+        foreach ($schema as $field => $definition)
80
+        {
79 81
             $optional = false;
80 82
 
81 83
             // short definition
82
-            if (is_string($definition)) {
84
+            if (is_string($definition))
85
+            {
83 86
                 // simple scalar field definition
84
-                if (!class_exists($definition)) {
87
+                if (!class_exists($definition))
88
+                {
85 89
                     [$source, $origin] = $this->parseDefinition($field, $definition);
86 90
                     $result[$field] = [
87 91
                         FilterProvider::SOURCE => $source,
@@ -102,25 +106,30 @@  discard block
 block discarded – undo
102 106
                 continue;
103 107
             }
104 108
 
105
-            if (!is_array($definition) || count($definition) === 0) {
109
+            if (!is_array($definition) || count($definition) === 0)
110
+            {
106 111
                 throw new SchemaException(
107 112
                     "Invalid schema definition at `{$filter->getName()}`->`{$field}`"
108 113
                 );
109 114
             }
110 115
 
111 116
             // complex definition
112
-            if (!empty($definition[self::ORIGIN])) {
117
+            if (!empty($definition[self::ORIGIN]))
118
+            {
113 119
                 $origin = $definition[self::ORIGIN];
114 120
 
115 121
                 // [class, 'data:something.*'] vs [class, 'data:something']
116 122
                 $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]);
117 123
                 $origin = rtrim($origin, '.*');
118
-            } else {
124
+            }
125
+            else
126
+            {
119 127
                 $origin = $field;
120 128
                 $iterate = true;
121 129
             }
122 130
 
123
-            if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) {
131
+            if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL])
132
+            {
124 133
                 $optional = true;
125 134
             }
126 135
 
@@ -133,7 +142,8 @@  discard block
 block discarded – undo
133 142
                 FilterProvider::OPTIONAL => $optional,
134 143
             ];
135 144
 
136
-            if ($iterate) {
145
+            if ($iterate)
146
+            {
137 147
                 [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin);
138 148
 
139 149
                 $map[FilterProvider::ITERATE_SOURCE] = $source;
@@ -159,7 +169,8 @@  discard block
 block discarded – undo
159 169
      */
160 170
     private function parseDefinition(string $field, string $definition): array
161 171
     {
162
-        if (strpos($definition, ':') === false) {
172
+        if (strpos($definition, ':') === false)
173
+        {
163 174
             return ['data', $definition ?? $field];
164 175
         }
165 176
 
Please login to merge, or discard this patch.
src/Filters/src/Filter.php 1 patch
Braces   +30 added lines, -15 removed lines patch added patch discarded remove patch
@@ -151,10 +151,13 @@  discard block
 block discarded – undo
151 151
      */
152 152
     public function getErrors(): array
153 153
     {
154
-        if ($this->errors === null) {
154
+        if ($this->errors === null)
155
+        {
155 156
             $this->errors = [];
156
-            foreach ($this->validator->withData($this)->getErrors() as $field => $error) {
157
-                if (is_string($error) && Translator::isMessage($error)) {
157
+            foreach ($this->validator->withData($this)->getErrors() as $field => $error)
158
+            {
159
+                if (is_string($error) && Translator::isMessage($error))
160
+                {
158 161
                     // translate error message
159 162
                     $error = $this->say($error);
160 163
                 }
@@ -178,32 +181,42 @@  discard block
 block discarded – undo
178 181
      */
179 182
     protected function validateNested(array $errors): array
180 183
     {
181
-        foreach ($this->getFields(false) as $index => $value) {
182
-            if (isset($errors[$index])) {
184
+        foreach ($this->getFields(false) as $index => $value)
185
+        {
186
+            if (isset($errors[$index]))
187
+            {
183 188
                 //Invalid on parent level
184 189
                 continue;
185 190
             }
186 191
 
187
-            if ($value instanceof FilterInterface) {
188
-                if ($this->isOptional($index) && ! $this->hasBeenPassed($index)) {
192
+            if ($value instanceof FilterInterface)
193
+            {
194
+                if ($this->isOptional($index) && ! $this->hasBeenPassed($index))
195
+                {
189 196
                     continue;
190 197
                 }
191 198
 
192
-                if (! $value->isValid()) {
199
+                if (! $value->isValid())
200
+                {
193 201
                     $errors[$index] = $value->getErrors();
194 202
                     continue;
195 203
                 }
196 204
             }
197 205
 
198 206
             //Array of nested entities for validation
199
-            if (is_iterable($value)) {
200
-                foreach ($value as $nIndex => $nValue) {
201
-                    if ($nValue instanceof FilterInterface) {
202
-                        if ($this->isOptional($nIndex) && ! $this->hasBeenPassed($nIndex)) {
207
+            if (is_iterable($value))
208
+            {
209
+                foreach ($value as $nIndex => $nValue)
210
+                {
211
+                    if ($nValue instanceof FilterInterface)
212
+                    {
213
+                        if ($this->isOptional($nIndex) && ! $this->hasBeenPassed($nIndex))
214
+                        {
203 215
                             continue;
204 216
                         }
205 217
 
206
-                        if (! $nValue->isValid()) {
218
+                        if (! $nValue->isValid())
219
+                        {
207 220
                             $errors[$index][$nIndex] = $nValue->getErrors();
208 221
                         }
209 222
                     }
@@ -237,11 +250,13 @@  discard block
 block discarded – undo
237 250
     {
238 251
         $value = $this->getField($field);
239 252
 
240
-        if ($value === null) {
253
+        if ($value === null)
254
+        {
241 255
             return false;
242 256
         }
243 257
 
244
-        if ($value instanceof FilterInterface) {
258
+        if ($value instanceof FilterInterface)
259
+        {
245 260
             return $value->getValue() !== [];
246 261
         }
247 262
 
Please login to merge, or discard this patch.