Passed
Pull Request — master (#450)
by Kirill
07:27
created
src/Filters/src/SchemaBuilder.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -70,18 +70,18 @@  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
             throw new SchemaException("Filter `{$filter->getName()}` does not define any schema");
75 75
         }
76 76
 
77 77
         $result = [];
78
-        foreach ($schema as $field => $definition) {
78
+        foreach ($schema as $field => $definition){
79 79
             $optional = false;
80 80
 
81 81
             // short definition
82
-            if (is_string($definition)) {
82
+            if (is_string($definition)){
83 83
                 // simple scalar field definition
84
-                if (!class_exists($definition)) {
84
+                if (!class_exists($definition)){
85 85
                     [$source, $origin] = $this->parseDefinition($field, $definition);
86 86
                     $result[$field] = [
87 87
                         FilterProvider::SOURCE => $source,
@@ -102,25 +102,25 @@  discard block
 block discarded – undo
102 102
                 continue;
103 103
             }
104 104
 
105
-            if (!is_array($definition) || count($definition) === 0) {
105
+            if (!is_array($definition) || count($definition) === 0){
106 106
                 throw new SchemaException(
107 107
                     "Invalid schema definition at `{$filter->getName()}`->`{$field}`"
108 108
                 );
109 109
             }
110 110
 
111 111
             // complex definition
112
-            if (!empty($definition[self::ORIGIN])) {
112
+            if (!empty($definition[self::ORIGIN])){
113 113
                 $origin = $definition[self::ORIGIN];
114 114
 
115 115
                 // [class, 'data:something.*'] vs [class, 'data:something']
116 116
                 $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]);
117 117
                 $origin = rtrim($origin, '.*');
118
-            } else {
118
+            }else{
119 119
                 $origin = $field;
120 120
                 $iterate = true;
121 121
             }
122 122
 
123
-            if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) {
123
+            if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]){
124 124
                 $optional = true;
125 125
             }
126 126
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
                 FilterProvider::OPTIONAL => $optional,
134 134
             ];
135 135
 
136
-            if ($iterate) {
136
+            if ($iterate){
137 137
                 [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin);
138 138
 
139 139
                 $map[FilterProvider::ITERATE_SOURCE] = $source;
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     private function parseDefinition(string $field, string $definition): array
161 161
     {
162
-        if (strpos($definition, ':') === false) {
162
+        if (strpos($definition, ':') === false){
163 163
             return ['data', $definition ?? $field];
164 164
         }
165 165
 
Please login to merge, or discard this patch.
src/Filters/src/Filter.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         array $schema,
90 90
         ValidatorInterface $validator,
91 91
         ErrorMapper $errorMapper
92
-    ) {
92
+    ){
93 93
         parent::__construct($data, $schema);
94 94
 
95 95
         $this->mappings = $schema[FilterProvider::MAPPING] ?? [];
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
      */
161 161
     public function getErrors(): array
162 162
     {
163
-        if ($this->errors === null) {
163
+        if ($this->errors === null){
164 164
             $this->errors = [];
165
-            foreach ($this->validator->withData($this)->getErrors() as $field => $error) {
166
-                if (is_string($error) && Translator::isMessage($error)) {
165
+            foreach ($this->validator->withData($this)->getErrors() as $field => $error){
166
+                if (is_string($error) && Translator::isMessage($error)){
167 167
                     // translate error message
168 168
                     $error = $this->say($error);
169 169
                 }
@@ -195,36 +195,36 @@  discard block
 block discarded – undo
195 195
      */
196 196
     protected function validateNested(array $errors): array
197 197
     {
198
-        foreach ($this->getFields(false) as $index => $value) {
199
-            if (isset($errors[$index])) {
198
+        foreach ($this->getFields(false) as $index => $value){
199
+            if (isset($errors[$index])){
200 200
                 //Invalid on parent level
201 201
                 continue;
202 202
             }
203 203
 
204
-            if ($value instanceof FilterInterface) {
204
+            if ($value instanceof FilterInterface){
205 205
                 $isOptional = $this->mappings[$index][FilterProvider::OPTIONAL] ?? false;
206 206
 
207
-                if ($isOptional && $this->getField($index) !== []) {
207
+                if ($isOptional && $this->getField($index) !== []){
208 208
                     continue;
209 209
                 }
210 210
 
211
-                if (!$value->isValid()) {
211
+                if (!$value->isValid()){
212 212
                     $errors[$index] = $value->getErrors();
213 213
                     continue;
214 214
                 }
215 215
             }
216 216
 
217 217
             //Array of nested entities for validation
218
-            if (is_iterable($value)) {
219
-                foreach ($value as $nIndex => $nValue) {
220
-                    if ($nValue instanceof FilterInterface) {
218
+            if (is_iterable($value)){
219
+                foreach ($value as $nIndex => $nValue){
220
+                    if ($nValue instanceof FilterInterface){
221 221
                         $isOptional = $this->mappings[$index][FilterProvider::OPTIONAL] ?? false;
222 222
 
223
-                        if ($isOptional && $this->getField($nIndex) !== []) {
223
+                        if ($isOptional && $this->getField($nIndex) !== []){
224 224
                             continue;
225 225
                         }
226 226
 
227
-                        if (!$nValue->isValid()) {
227
+                        if (!$nValue->isValid()){
228 228
                             $errors[$index][$nIndex] = $nValue->getErrors();
229 229
                         }
230 230
                     }
Please login to merge, or discard this patch.