@@ -2,23 +2,23 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace HnrAzevedo\Validator; |
| 4 | 4 | |
| 5 | -Trait Check{ |
|
| 5 | +Trait Check { |
|
| 6 | 6 | use ExtraCheck; |
| 7 | 7 | |
| 8 | 8 | protected static function check_minlength(string $param, $value) |
| 9 | 9 | { |
| 10 | - if(self::toNext($param,$value)){ |
|
| 10 | + if (self::toNext($param, $value)) { |
|
| 11 | 11 | |
| 12 | 12 | $realval = (is_array(json_decode(self::$data['data'])->$param)) ? json_decode(self::$data['data'])->$param : [json_decode(self::$data['data'])->$param]; |
| 13 | 13 | |
| 14 | - foreach($realval as $val){ |
|
| 15 | - if(strlen($val) === 0) { |
|
| 14 | + foreach ($realval as $val) { |
|
| 15 | + if (strlen($val)===0) { |
|
| 16 | 16 | self::$errors[] = [ |
| 17 | 17 | $param => 'é obrigatório.' |
| 18 | 18 | ]; |
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - if($value > strlen($val)) { |
|
| 21 | + if ($value>strlen($val)) { |
|
| 22 | 22 | self::$errors[] = [ |
| 23 | 23 | $param => 'não atingiu o mínimo de caracteres esperado.' |
| 24 | 24 | ]; |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | protected static function check_regex(string $param, $value) |
| 31 | 31 | { |
| 32 | - if(self::toNext($param,$value)){ |
|
| 32 | + if (self::toNext($param, $value)) { |
|
| 33 | 33 | |
| 34 | 34 | $realval = (is_array(json_decode(self::$data['data'])->$param)) ? json_decode(self::$data['data'])->$param : [json_decode(self::$data['data'])->$param]; |
| 35 | 35 | |
| 36 | - foreach($realval as $val){ |
|
| 36 | + foreach ($realval as $val) { |
|
| 37 | 37 | |
| 38 | - if(!preg_match(self::$validators[self::$model]->getRules(self::$data['role'])[$param]['regex'], $val)){ |
|
| 38 | + if (!preg_match(self::$validators[self::$model]->getRules(self::$data['role'])[$param]['regex'], $val)) { |
|
| 39 | 39 | self::$errors[] = [ |
| 40 | 40 | $param => 'inválido(a).' |
| 41 | 41 | ]; |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | protected static function check_mincount(string $param, $value) |
| 49 | 49 | { |
| 50 | - if(self::toNext($param,$value)){ |
|
| 50 | + if (self::toNext($param, $value)) { |
|
| 51 | 51 | $array = self::testArray($param, json_decode(self::$data['data'])->$param); |
| 52 | - if(count($array) < $value){ |
|
| 52 | + if (count($array)<$value) { |
|
| 53 | 53 | self::$errors[] = [ |
| 54 | 54 | $param => 'não atingiu o mínimo esperado.' |
| 55 | 55 | ]; |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | protected static function check_maxcount(string $param, $value) |
| 61 | 61 | { |
| 62 | - if(self::toNext($param,$value)){ |
|
| 62 | + if (self::toNext($param, $value)) { |
|
| 63 | 63 | $array = self::testArray($param, json_decode(self::$data['data'])->$param); |
| 64 | - if(count($array) > $value){ |
|
| 64 | + if (count($array)>$value) { |
|
| 65 | 65 | self::$errors[] = [ |
| 66 | 66 | $param => 'ultrapassou o esperado.' |
| 67 | 67 | ]; |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | protected static function check_equals(string $param, $value) |
| 73 | 73 | { |
| 74 | - if(self::toNext($param,$value)){ |
|
| 74 | + if (self::toNext($param, $value)) { |
|
| 75 | 75 | |
| 76 | - if(!array_key_exists($param,json_decode(self::$data['data'],true))){ |
|
| 76 | + if (!array_key_exists($param, json_decode(self::$data['data'], true))) { |
|
| 77 | 77 | self::$errors[] = [ |
| 78 | 78 | $param => "O servidor não encontrou a informação '{$value}' para ser comparada." |
| 79 | 79 | ]; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(json_decode(self::$data['data'])->$param != json_decode(self::$data['data'],true)[$value]){ |
|
| 82 | + if (json_decode(self::$data['data'])->$param!=json_decode(self::$data['data'], true)[$value]) { |
|
| 83 | 83 | self::$errors[] = [ |
| 84 | 84 | $param => 'está diferente de '.ucfirst($value) |
| 85 | 85 | ]; |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | protected static function check_maxlength(string $param, $value) |
| 92 | 92 | { |
| 93 | - if(self::toNext($param,$value)){ |
|
| 93 | + if (self::toNext($param, $value)) { |
|
| 94 | 94 | |
| 95 | 95 | $realval = (is_array(json_decode(self::$data['data'])->$param)) ? json_decode(self::$data['data'])->$param : [json_decode(self::$data['data'])->$param]; |
| 96 | 96 | |
| 97 | - foreach($realval as $val){ |
|
| 97 | + foreach ($realval as $val) { |
|
| 98 | 98 | |
| 99 | - if($value < strlen($val)) { |
|
| 99 | + if ($value<strlen($val)) { |
|
| 100 | 100 | self::$errors[] = [ |
| 101 | 101 | $param => 'ultrapassou o máximo de caracteres esperado.' |
| 102 | 102 | ]; |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | protected static function check_type(string $param, $value) |
| 110 | 110 | { |
| 111 | - if(self::toNext($param,$value)){ |
|
| 111 | + if (self::toNext($param, $value)) { |
|
| 112 | 112 | |
| 113 | 113 | switch ($value) { |
| 114 | 114 | case 'date': |
| 115 | - if(!self::validateDate(json_decode(self::$data['data'])->$param , 'd/m/Y')){ |
|
| 115 | + if (!self::validateDate(json_decode(self::$data['data'])->$param, 'd/m/Y')) { |
|
| 116 | 116 | self::$errors[] = [ |
| 117 | 117 | $param => 'não é uma data válida.' |
| 118 | 118 | ]; |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | protected static function check_filter(string $param, $value) |
| 126 | 126 | { |
| 127 | - if(self::toNext($param,$value)){ |
|
| 127 | + if (self::toNext($param, $value)) { |
|
| 128 | 128 | |
| 129 | - if(!filter_var(json_decode(self::$data['data'])->$param, $value)){ |
|
| 129 | + if (!filter_var(json_decode(self::$data['data'])->$param, $value)) { |
|
| 130 | 130 | self::$errors[] = [ |
| 131 | 131 | $param => 'não passou pela filtragem de dados.' |
| 132 | 132 | ]; |