Passed
Push — master ( c6e4cd...5de612 )
by Darío
01:48
created
src/Validator/FormValidator.php 1 patch
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -69,9 +69,10 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function isValid()
71 71
     {
72
-        if (is_null($this->valid))
73
-            # This error is thrown because of 'setValid' method has not been executed.
72
+        if (is_null($this->valid)) {
73
+                    # This error is thrown because of 'setValid' method has not been executed.
74 74
             throw new \LogicException('No validation has been executed!');
75
+        }
75 76
 
76 77
         return $this->valid;
77 78
     }
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
     {
99 100
         $this->form = $form;
100 101
 
101
-        if (is_null($locale))
102
-            $locale = 'en';
102
+        if (is_null($locale)) {
103
+                    $locale = 'en';
104
+        }
103 105
 
104 106
         $i18nTranslator = \Zend\I18n\Translator\Translator::factory(
105 107
             [
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 
134 136
         foreach ($elements as $label => $element)
135 137
         {
136
-            if (!$element->isFormControl())
137
-                continue;
138
+            if (!$element->isFormControl()) {
139
+                            continue;
140
+            }
138 141
 
139 142
             $attribs = $element->getAttributes();
140 143
 
@@ -203,19 +206,21 @@  discard block
 block discarded – undo
203 206
 
204 207
                     case 'min':
205 208
 
206
-                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range']))
207
-                            $validator = new GreaterThan(['min' => $value, 'inclusive' => true]);
208
-                        else
209
-                            throw new \LogicException("The input type must be 'range' or 'number'");
209
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) {
210
+                                                    $validator = new GreaterThan(['min' => $value, 'inclusive' => true]);
211
+                        } else {
212
+                                                    throw new \LogicException("The input type must be 'range' or 'number'");
213
+                        }
210 214
 
211 215
                         break;
212 216
 
213 217
                     case 'max':
214 218
 
215
-                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range']))
216
-                            $validator = new LessThan(['max' => $value, 'inclusive' => true]);
217
-                        else
218
-                            throw new \LogicException("The input type must be 'range' or 'number'");
219
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) {
220
+                                                    $validator = new LessThan(['max' => $value, 'inclusive' => true]);
221
+                        } else {
222
+                                                    throw new \LogicException("The input type must be 'range' or 'number'");
223
+                        }
219 224
 
220 225
                         break;
221 226
 
@@ -223,17 +228,19 @@  discard block
 block discarded – undo
223 228
 
224 229
                         $baseValue = (array_key_exists('min', $all_attribs)) ? $all_attribs['min'] : 0;
225 230
 
226
-                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range']))
227
-                            $validator = new Step(['baseValue' => $baseValue, 'step' => $value]);
228
-                        else
229
-                            throw new \LogicException("The input type must be 'range'");
231
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) {
232
+                                                    $validator = new Step(['baseValue' => $baseValue, 'step' => $value]);
233
+                        } else {
234
+                                                    throw new \LogicException("The input type must be 'range'");
235
+                        }
230 236
 
231 237
                         break;
232 238
 
233 239
                     case 'data-validators':
234 240
 
235
-                        if (!is_array($value))
236
-                            throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute.");
241
+                        if (!is_array($value)) {
242
+                                                    throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute.");
243
+                        }
237 244
 
238 245
                         foreach ($value as $class => $params)
239 246
                         {
@@ -243,8 +250,9 @@  discard block
 block discarded – undo
243 250
                             {
244 251
                                 $className = "\Zend\I18n\Validator\\" . $class;
245 252
 
246
-                                if (!class_exists($className))
247
-                                    throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists");
253
+                                if (!class_exists($className)) {
254
+                                                                    throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists");
255
+                                }
248 256
                             }
249 257
 
250 258
                             $validator = new $className($params);
@@ -291,8 +299,9 @@  discard block
 block discarded – undo
291 299
             $v->setTranslator($this->translator);
292 300
             $notEmpty = $v->isValid($val);
293 301
 
294
-            if (!$required && !$notEmpty)
295
-                return null;
302
+            if (!$required && !$notEmpty) {
303
+                            return null;
304
+            }
296 305
 
297 306
             $valid = $validator->isValid($val);
298 307
             $this->setValid($valid);
@@ -304,8 +313,7 @@  discard block
 block discarded – undo
304 313
                     $this->error($label ."-~-". (count($this->getErrors()) + 1), $message);
305 314
                 }
306 315
             }
307
-        }
308
-        else
316
+        } else
309 317
         {
310 318
             foreach ($form_value as $val)
311 319
             {
@@ -330,8 +338,9 @@  discard block
 block discarded – undo
330 338
                 $errorLbl = explode("-~-", $key);
331 339
                 $label = array_shift($errorLbl);
332 340
 
333
-                if (!array_key_exists($label, $errors))
334
-                    $errors[$label] = [];
341
+                if (!array_key_exists($label, $errors)) {
342
+                                    $errors[$label] = [];
343
+                }
335 344
 
336 345
                 $errors[$label][] = $value;
337 346
             }
Please login to merge, or discard this patch.