Passed
Push — master ( 06d537...c6e4cd )
by Darío
01:59
created
src/Error/ErrorTrait.php 1 patch
Braces   +17 added lines, -13 removed lines patch added patch discarded remove patch
@@ -92,29 +92,32 @@  discard block
 block discarded – undo
92 92
      */
93 93
     protected function _error($code, $message = null)
94 94
     {
95
-        if (!is_null($code) && !is_integer($code) && !is_string($code))
96
-            throw new \InvalidArgumentException("Invalid type given. Integer or string expected");
95
+        if (!is_null($code) && !is_integer($code) && !is_string($code)) {
96
+                    throw new \InvalidArgumentException("Invalid type given. Integer or string expected");
97
+        }
97 98
 
98
-        if (is_null($code))
99
-            $code = preg_replace('/=|\/|\+/', "", base64_encode($message));
100
-        else
99
+        if (is_null($code)) {
100
+                    $code = preg_replace('/=|\/|\+/', "", base64_encode($message));
101
+        } else
101 102
         {
102
-            if (!array_key_exists($code, $this->standardErrors) && empty($message))
103
-                /*
103
+            if (!array_key_exists($code, $this->standardErrors) && empty($message)) {
104
+                            /*
104 105
                  * Non-standard errors must have a message to describe the error, make sure
105 106
                  * you execute the error() method with a message as the second parameter.
106 107
                  */
107 108
                 throw new \LogicException('The message does not be empty in non-standard errors!');
109
+            }
108 110
         }
109 111
 
110
-        if (!array_key_exists($code, $this->errors))
111
-            $this->errors[$code] = (array_key_exists($code, $this->standardErrors))
112
+        if (!array_key_exists($code, $this->errors)) {
113
+                    $this->errors[$code] = (array_key_exists($code, $this->standardErrors))
112 114
                 ?
113 115
                     is_null($message)
114 116
                         ? preg_replace('/\s\'%[a-zA-Z]*%\'/', $message, $this->standardErrors[$code])
115 117
                         # if $message is not null it will replace the %file% wildcard
116 118
                         : preg_replace('/%[a-zA-Z]*%/', $message, $this->standardErrors[$code])
117 119
                 : $message;
120
+        }
118 121
     }
119 122
 
120 123
     function __call($method, $arguments)
@@ -124,10 +127,11 @@  discard block
 block discarded – undo
124 127
             switch (count($arguments))
125 128
             {
126 129
                 case 1:
127
-                    if (is_integer($arguments[0]))
128
-                        return call_user_func([$this, '_error'], array_shift($arguments));
129
-                    else
130
-                        return call_user_func([$this, '_error'], null, array_shift($arguments));
130
+                    if (is_integer($arguments[0])) {
131
+                                            return call_user_func([$this, '_error'], array_shift($arguments));
132
+                    } else {
133
+                                            return call_user_func([$this, '_error'], null, array_shift($arguments));
134
+                    }
131 135
                     break;
132 136
                 case 2:
133 137
                     return call_user_func([$this, '_error'], $arguments[0], $arguments[1]);
Please login to merge, or discard this patch.
src/Validator/FormValidator.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -304,7 +304,7 @@
 block discarded – undo
304 304
             {
305 305
                 foreach ($validator->getMessages() as $message)
306 306
                 {
307
-                    $this->error($label ."-~-". (count($this->getErrors()) + 1), $message);
307
+                    $this->error($label . "-~-" . (count($this->getErrors()) + 1), $message);
308 308
                 }
309 309
             }
310 310
         }
Please login to merge, or discard this patch.
Braces   +34 added lines, -26 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
     }
@@ -136,8 +137,9 @@  discard block
 block discarded – undo
136 137
 
137 138
         foreach ($elements as $label => $element)
138 139
         {
139
-            if (!$element->isFormControl())
140
-                continue;
140
+            if (!$element->isFormControl()) {
141
+                            continue;
142
+            }
141 143
 
142 144
             $attribs = $element->getAttributes();
143 145
 
@@ -206,19 +208,21 @@  discard block
 block discarded – undo
206 208
 
207 209
                     case 'min':
208 210
 
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'");
211
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) {
212
+                                                    $validator = new GreaterThan(['min' => $value, 'inclusive' => true]);
213
+                        } else {
214
+                                                    throw new \LogicException("The input type must be 'range' or 'number'");
215
+                        }
213 216
 
214 217
                         break;
215 218
 
216 219
                     case 'max':
217 220
 
218
-                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range']))
219
-                            $validator = new LessThan(['max' => $value, 'inclusive' => true]);
220
-                        else
221
-                            throw new \LogicException("The input type must be 'range' or 'number'");
221
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) {
222
+                                                    $validator = new LessThan(['max' => $value, 'inclusive' => true]);
223
+                        } else {
224
+                                                    throw new \LogicException("The input type must be 'range' or 'number'");
225
+                        }
222 226
 
223 227
                         break;
224 228
 
@@ -226,17 +230,19 @@  discard block
 block discarded – undo
226 230
 
227 231
                         $baseValue = (array_key_exists('min', $all_attribs)) ? $all_attribs['min'] : 0;
228 232
 
229
-                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range']))
230
-                            $validator = new Step(['baseValue' => $baseValue, 'step' => $value]);
231
-                        else
232
-                            throw new \LogicException("The input type must be 'range'");
233
+                        if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) {
234
+                                                    $validator = new Step(['baseValue' => $baseValue, 'step' => $value]);
235
+                        } else {
236
+                                                    throw new \LogicException("The input type must be 'range'");
237
+                        }
233 238
 
234 239
                         break;
235 240
 
236 241
                     case 'data-validators':
237 242
 
238
-                        if (!is_array($value))
239
-                            throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute.");
243
+                        if (!is_array($value)) {
244
+                                                    throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute.");
245
+                        }
240 246
 
241 247
                         foreach ($value as $class => $params)
242 248
                         {
@@ -246,8 +252,9 @@  discard block
 block discarded – undo
246 252
                             {
247 253
                                 $className = "\Zend\I18n\Validator\\" . $class;
248 254
 
249
-                                if (!class_exists($className))
250
-                                    throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists");
255
+                                if (!class_exists($className)) {
256
+                                                                    throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists");
257
+                                }
251 258
                             }
252 259
 
253 260
                             $validator = new $className($params);
@@ -294,8 +301,9 @@  discard block
 block discarded – undo
294 301
             $v->setTranslator($this->translator);
295 302
             $notEmpty = $v->isValid($val);
296 303
 
297
-            if (!$required && !$notEmpty)
298
-                return null;
304
+            if (!$required && !$notEmpty) {
305
+                            return null;
306
+            }
299 307
 
300 308
             $valid = $validator->isValid($val);
301 309
             $this->setValid($valid);
@@ -307,8 +315,7 @@  discard block
 block discarded – undo
307 315
                     $this->error($label ."-~-". (count($this->getErrors()) + 1), $message);
308 316
                 }
309 317
             }
310
-        }
311
-        else
318
+        } else
312 319
         {
313 320
             foreach ($form_value as $val)
314 321
             {
@@ -333,8 +340,9 @@  discard block
 block discarded – undo
333 340
                 $errorLbl = explode("-~-", $key);
334 341
                 $label = array_shift($errorLbl);
335 342
 
336
-                if (!array_key_exists($label, $errors))
337
-                    $errors[$label] = [];
343
+                if (!array_key_exists($label, $errors)) {
344
+                                    $errors[$label] = [];
345
+                }
338 346
 
339 347
                 $errors[$label][] = $value;
340 348
             }
Please login to merge, or discard this patch.