Passed
Branch master (d9287e)
by refat
05:38
created
Core/System/Validation/Validator.php 1 patch
Braces   +93 added lines, -31 removed lines patch added patch discarded remove patch
@@ -75,7 +75,9 @@  discard block
 block discarded – undo
75 75
    */
76 76
   public function require($call = true, $msg = null)
77 77
   {
78
-    if ($call === false) return $this;
78
+    if ($call === false) {
79
+      return $this;
80
+    }
79 81
 
80 82
     $value = $this->value();
81 83
 
@@ -107,11 +109,15 @@  discard block
 block discarded – undo
107 109
    */
108 110
   public function email($call = true, $msg = null)
109 111
   {
110
-    if ($call === false) return $this;
112
+    if ($call === false) {
113
+      return $this;
114
+    }
111 115
 
112 116
     $value = $this->value();
113 117
 
114
-    if (!$value && $value != '0') return $this;
118
+    if (!$value && $value != '0') {
119
+      return $this;
120
+    }
115 121
 
116 122
     if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
117 123
       $msg = $msg ?: 'e-mail is not valid';
@@ -130,11 +136,15 @@  discard block
 block discarded – undo
130 136
    */
131 137
   public function image($call = true, $msg = null)
132 138
   {
133
-    if ($call === false) return $this;
139
+    if ($call === false) {
140
+      return $this;
141
+    }
134 142
 
135 143
     $file = $this->app->request->file($this->input);
136 144
 
137
-    if (!$file->exists()) return $this;
145
+    if (!$file->exists()) {
146
+      return $this;
147
+    }
138 148
 
139 149
     if (!$file->isImage()) {
140 150
       $msg = $msg ?: 'image is not valid';
@@ -153,11 +163,15 @@  discard block
 block discarded – undo
153 163
    */
154 164
   public function number($call = true, $msg = null)
155 165
   {
156
-    if ($call === false) return $this;
166
+    if ($call === false) {
167
+      return $this;
168
+    }
157 169
 
158 170
     $value = $this->value();
159 171
 
160
-    if (!$value && $value != '0') return $this;
172
+    if (!$value && $value != '0') {
173
+      return $this;
174
+    }
161 175
 
162 176
     if (!is_numeric($value)) {
163 177
       $msg = $msg ?: 'this field must be a number';
@@ -176,11 +190,15 @@  discard block
 block discarded – undo
176 190
    */
177 191
   public function float($call = true, $msg = null)
178 192
   {
179
-    if ($call === false) return $this;
193
+    if ($call === false) {
194
+      return $this;
195
+    }
180 196
 
181 197
     $value = $this->value();
182 198
 
183
-    if (!$value && $value != '0') return $this;
199
+    if (!$value && $value != '0') {
200
+      return $this;
201
+    }
184 202
 
185 203
     if (!is_float($value)) {
186 204
       $msg = $msg ?: "this field must be a float number";
@@ -201,11 +219,15 @@  discard block
 block discarded – undo
201 219
    */
202 220
   public function date($options = [], $msg = null)
203 221
   {
204
-    if ($options === false) return $this;
222
+    if ($options === false) {
223
+      return $this;
224
+    }
205 225
 
206 226
     $value = $this->value();
207 227
 
208
-    if (!$value && $value != '0') return $this;
228
+    if (!$value && $value != '0') {
229
+      return $this;
230
+    }
209 231
 
210 232
     $options = json_encode($options);
211 233
     $options = json_decode($options);
@@ -234,11 +256,15 @@  discard block
 block discarded – undo
234 256
    */
235 257
   public function text($call = true, $msg = null)
236 258
   {
237
-    if ($call === false) return $this;
259
+    if ($call === false) {
260
+      return $this;
261
+    }
238 262
 
239 263
     $value = $this->value();
240 264
 
241
-    if (!$value && $value != '0') return $this;
265
+    if (!$value && $value != '0') {
266
+      return $this;
267
+    }
242 268
 
243 269
     if (!is_string($value)) {
244 270
       $msg = $msg ?: 'the field must be a text';
@@ -257,11 +283,15 @@  discard block
 block discarded – undo
257 283
    */
258 284
   public function noNumbers($call = true, $msg = null)
259 285
   {
260
-    if ($call === false) return $this;
286
+    if ($call === false) {
287
+      return $this;
288
+    }
261 289
 
262 290
     $value = $this->value();
263 291
 
264
-    if (!$value && $value != '0') return $this;
292
+    if (!$value && $value != '0') {
293
+      return $this;
294
+    }
265 295
 
266 296
     if (preg_match('~[0-9]~', $value)) {
267 297
       $msg = $msg ?: 'numbers are not allow';
@@ -280,11 +310,15 @@  discard block
 block discarded – undo
280 310
    */
281 311
   public function characters($excepts, $msg = null)
282 312
   {
283
-    if ($excepts === false) return $this;
313
+    if ($excepts === false) {
314
+      return $this;
315
+    }
284 316
 
285 317
     $value = $this->value();
286 318
 
287
-    if (!$value && $value != '0') return $this;
319
+    if (!$value && $value != '0') {
320
+      return $this;
321
+    }
288 322
 
289 323
     $characters = new Characters($excepts, $value);
290 324
 
@@ -315,11 +349,15 @@  discard block
 block discarded – undo
315 349
    */
316 350
   public function noSpaces($call = true, $msg = null)
317 351
   {
318
-    if ($call === false) return $this;
352
+    if ($call === false) {
353
+      return $this;
354
+    }
319 355
 
320 356
     $value = $this->value();
321 357
 
322
-    if (!$value && $value != '0') return $this;
358
+    if (!$value && $value != '0') {
359
+      return $this;
360
+    }
323 361
 
324 362
     if (preg_match('/\s/', $value)) {
325 363
       $msg = $msg ?: 'spaces are not allow';
@@ -338,11 +376,15 @@  discard block
 block discarded – undo
338 376
    */
339 377
   public function alloweJust($characters = [], $msg = null)
340 378
   {
341
-    if ($characters === false) return $this;
379
+    if ($characters === false) {
380
+      return $this;
381
+    }
342 382
 
343 383
     $value = $this->value();
344 384
 
345
-    if (!$value && $value != '0') return $this;
385
+    if (!$value && $value != '0') {
386
+      return $this;
387
+    }
346 388
 
347 389
     $allowedCharacters = new AlloweJust($this->app, $characters);
348 390
     $characters = $allowedCharacters->getCharacters();
@@ -363,11 +405,15 @@  discard block
 block discarded – undo
363 405
    */
364 406
   public function length($length = null, $msg = null)
365 407
   {
366
-    if ($length === false) return $this;
408
+    if ($length === false) {
409
+      return $this;
410
+    }
367 411
 
368 412
     $value = $this->value();
369 413
 
370
-    if (!$value && $value != '0') return $this;
414
+    if (!$value && $value != '0') {
415
+      return $this;
416
+    }
371 417
 
372 418
     if (strlen($value) !== $length) {
373 419
       $msg = $msg ?: `this field can be just ${length} charachter`;
@@ -386,11 +432,15 @@  discard block
 block discarded – undo
386 432
    */
387 433
   public function maxLen($length = null, $msg = null)
388 434
   {
389
-    if ($length === false) return $this;
435
+    if ($length === false) {
436
+      return $this;
437
+    }
390 438
 
391 439
     $value = $this->value();
392 440
 
393
-    if (!$value && $value != '0') return $this;
441
+    if (!$value && $value != '0') {
442
+      return $this;
443
+    }
394 444
 
395 445
     if (strlen($value) > $length) {
396 446
       $msg = $msg ?: "this field can be maximum $length charachter";
@@ -409,11 +459,15 @@  discard block
 block discarded – undo
409 459
    */
410 460
   public function minLen($length = null, $msg = null)
411 461
   {
412
-    if ($length === false) return $this;
462
+    if ($length === false) {
463
+      return $this;
464
+    }
413 465
 
414 466
     $value = $this->value();
415 467
 
416
-    if (!$value && $value != '0') return $this;
468
+    if (!$value && $value != '0') {
469
+      return $this;
470
+    }
417 471
 
418 472
     if (strlen($value) < $length) {
419 473
       $msg = $msg ?: "this field can be minimum $length charachter";
@@ -432,7 +486,9 @@  discard block
 block discarded – undo
432 486
    */
433 487
   public function match($input, $msg = null)
434 488
   {
435
-    if ($input === false) return $this;
489
+    if ($input === false) {
490
+      return $this;
491
+    }
436 492
 
437 493
     $value = $this->value();
438 494
 
@@ -457,11 +513,15 @@  discard block
 block discarded – undo
457 513
    */
458 514
   public function unique($data = [], $msg = null)
459 515
   {
460
-    if ($data === false) return $this;
516
+    if ($data === false) {
517
+      return $this;
518
+    }
461 519
 
462 520
     $value = $this->value();
463 521
 
464
-    if (!$data) return $this;
522
+    if (!$data) {
523
+      return $this;
524
+    }
465 525
 
466 526
     if (is_array($data)) {
467 527
       list($table, $column) = $data;
@@ -519,7 +579,9 @@  discard block
 block discarded – undo
519 579
    */
520 580
   public function addError($input, $msg)
521 581
   {
522
-    if (!$this->hasError($input)) $this->errors[$input] = $msg;
582
+    if (!$this->hasError($input)) {
583
+      $this->errors[$input] = $msg;
584
+    }
523 585
   }
524 586
 
525 587
   /**
Please login to merge, or discard this patch.