@@ -9,30 +9,30 @@ |
||
9 | 9 | |
10 | 10 | public function __construct(object $model) |
11 | 11 | { |
12 | - $this->form['model'] = ucfirst(get_class($model)); |
|
13 | - } |
|
12 | + $this->form['model'] = ucfirst(get_class($model)); |
|
13 | + } |
|
14 | 14 | |
15 | 15 | public function setAction(string $action): Rules |
16 | 16 | { |
17 | - $this->action = $action; |
|
18 | - return $this; |
|
19 | - } |
|
17 | + $this->action = $action; |
|
18 | + return $this; |
|
19 | + } |
|
20 | 20 | |
21 | 21 | public function addField(string $field, array $test): Rules |
22 | 22 | { |
23 | - if(empty($this->action)){ |
|
23 | + if(empty($this->action)){ |
|
24 | 24 | self::$errors[] = "Form action not registered."; |
25 | 25 | } |
26 | 26 | |
27 | - if(empty($this->form[$this->action][$field])){ |
|
27 | + if(empty($this->form[$this->action][$field])){ |
|
28 | 28 | $this->form[$this->action][$field] = $test; |
29 | 29 | } |
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | public function getRules(string $action): ?array |
35 | 35 | { |
36 | - return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
37 | - } |
|
36 | + return (array_key_exists($action, $this->form)) ? $this->form[$action] : null; |
|
37 | + } |
|
38 | 38 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Validator; |
4 | 4 | |
5 | -Class Rules{ |
|
5 | +Class Rules { |
|
6 | 6 | private string $action; |
7 | 7 | protected static array $errors = []; |
8 | 8 | |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | |
22 | 22 | public function addField(string $field, array $test): Rules |
23 | 23 | { |
24 | - if(empty($this->action)){ |
|
24 | + if (empty($this->action)) { |
|
25 | 25 | self::$errors[] = "Form action not registered."; |
26 | 26 | } |
27 | 27 | |
28 | - if(empty($this->form[$this->action][$field])){ |
|
28 | + if (empty($this->form[$this->action][$field])) { |
|
29 | 29 | $this->form[$this->action][$field] = $test; |
30 | 30 | } |
31 | 31 |
@@ -12,15 +12,15 @@ |
||
12 | 12 | |
13 | 13 | Validator::add($this, function(Rules $rules){ |
14 | 14 | $rules->setAction('login') |
15 | - //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
16 | - ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
17 | - ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
18 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
19 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
20 | - ->addField('birth',['type'=>'date','required'=>true]) |
|
21 | - ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
22 | - |
|
23 | - return $rules; |
|
15 | + //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
|
16 | + ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
17 | + ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
18 | + ->addField('password2',['equals'=>'password','required'=>true]) |
|
19 | + ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
20 | + ->addField('birth',['type'=>'date','required'=>true]) |
|
21 | + ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
22 | + |
|
23 | + return $rules; |
|
24 | 24 | }); |
25 | 25 | |
26 | 26 | return $this; |
@@ -5,20 +5,20 @@ |
||
5 | 5 | use HnrAzevedo\Validator\Validator; |
6 | 6 | use HnrAzevedo\Validator\Rules; |
7 | 7 | |
8 | -Class User{ |
|
8 | +Class User { |
|
9 | 9 | |
10 | 10 | public function __construct() |
11 | 11 | { |
12 | 12 | |
13 | - Validator::add($this, function(Rules $rules){ |
|
13 | + Validator::add($this, function(Rules $rules) { |
|
14 | 14 | $rules->setAction('login') |
15 | 15 | //->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true]) |
16 | - ->addField('email',['minlength'=>1,'filter'=>FILTER_VALIDATE_EMAIL,'required'=>true]) |
|
17 | - ->addField('password',['minlength'=>6,'maxlength'=>20,'required'=>true]) |
|
18 | - ->addField('password2',['equals'=>'password','required'=>true]) |
|
19 | - ->addField('remember',['minlength'=>2,'maxlength'=>2,'required'=>false]) |
|
20 | - ->addField('birth',['type'=>'date','required'=>true]) |
|
21 | - ->addField('phones',['mincount'=>2,'maxcount'=>3,'required'=>true,'minlength'=>8,'maxlength'=>9]); |
|
16 | + ->addField('email', ['minlength'=>1, 'filter'=>FILTER_VALIDATE_EMAIL, 'required'=>true]) |
|
17 | + ->addField('password', ['minlength'=>6, 'maxlength'=>20, 'required'=>true]) |
|
18 | + ->addField('password2', ['equals'=>'password', 'required'=>true]) |
|
19 | + ->addField('remember', ['minlength'=>2, 'maxlength'=>2, 'required'=>false]) |
|
20 | + ->addField('birth', ['type'=>'date', 'required'=>true]) |
|
21 | + ->addField('phones', ['mincount'=>2, 'maxcount'=>3, 'required'=>true, 'minlength'=>8, 'maxlength'=>9]); |
|
22 | 22 | |
23 | 23 | return $rules; |
24 | 24 | }); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Validator; |
4 | 4 | |
5 | -Trait ExtraCheck{ |
|
5 | +Trait ExtraCheck { |
|
6 | 6 | protected static array $data = []; |
7 | 7 | protected static array $validators = []; |
8 | 8 | protected static string $model = ''; |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | |
12 | 12 | protected static function checkRequireds() |
13 | 13 | { |
14 | - if(count(self::$required) > 0){ |
|
14 | + if (count(self::$required)>0) { |
|
15 | 15 | self::$errors[] = [ |
16 | - 'As seguintes informações não poderam ser validadas: '.implode(', ',array_keys(self::$required)).'.' |
|
16 | + 'As seguintes informações não poderam ser validadas: '.implode(', ', array_keys(self::$required)).'.' |
|
17 | 17 | ]; |
18 | 18 | } |
19 | 19 | } |
@@ -21,22 +21,22 @@ discard block |
||
21 | 21 | public static function validateDate($date, $format = 'Y-m-d H:i:s') |
22 | 22 | { |
23 | 23 | $d = \DateTime::createFromFormat($format, $date); |
24 | - return $d && $d->format($format) == $date; |
|
24 | + return $d && $d->format($format)==$date; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | protected static function checkRequired(string $param): bool |
28 | 28 | { |
29 | - return (array_key_exists('required',self::$validators[self::$model]->getRules(self::$data['role'])[$param]) && self::$validators[self::$model]->getRules(self::$data['role'])[$param]['required']); |
|
29 | + return (array_key_exists('required', self::$validators[self::$model]->getRules(self::$data['role'])[$param]) && self::$validators[self::$model]->getRules(self::$data['role'])[$param]['required']); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | protected static function toNext(string $param, $value) |
33 | 33 | { |
34 | - return (self::checkRequired($param) || strlen($value > 0)); |
|
34 | + return (self::checkRequired($param) || strlen($value>0)); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | protected static function testArray(string $param, $value): ?array |
38 | 38 | { |
39 | - if(!is_array(json_decode($value))){ |
|
39 | + if (!is_array(json_decode($value))) { |
|
40 | 40 | self::$errors[] = [ |
41 | 41 | $param => 'Era esperado uma informação em formato array para está informação.' |
42 | 42 | ]; |
@@ -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 checkMinlength(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 checkRegex(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 checkMincount(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 checkMaxcount(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 checkEquals(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 checkMaxlength(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 checkType(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 checkFilter(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 | ]; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public static function checkDatas() |
64 | 64 | { |
65 | - self::existData(); |
|
65 | + self::existData(); |
|
66 | 66 | self::jsonData(); |
67 | 67 | self::hasProvider(); |
68 | 68 | self::hasRole(); |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | |
79 | 79 | self::$model = self::getClass($model); |
80 | 80 | |
81 | - self::existRole(self::$model); |
|
81 | + self::existRole(self::$model); |
|
82 | 82 | |
83 | - foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
83 | + foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
84 | 84 | if(@$value['required'] === true){ |
85 | 85 | self::$required[$key] = $value; |
86 | 86 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | self::checkRequireds(); |
94 | 94 | |
95 | - return self::checkErrors(); |
|
95 | + return self::checkErrors(); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public static function checkErrors(): bool |
@@ -104,23 +104,23 @@ discard block |
||
104 | 104 | { |
105 | 105 | foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
106 | 106 | |
107 | - foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
107 | + foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
|
108 | 108 | |
109 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
109 | + if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
110 | 110 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
111 | 111 | } |
112 | 112 | |
113 | - if($keyy===$key){ |
|
113 | + if($keyy===$key){ |
|
114 | 114 | |
115 | 115 | unset(self::$required[$key]); |
116 | 116 | |
117 | - foreach ($value as $subkey => $subvalue) { |
|
117 | + foreach ($value as $subkey => $subvalue) { |
|
118 | 118 | $function = "check".ucfirst($subkey); |
119 | 119 | self::testMethod($function); |
120 | 120 | self::$function($keyy,$subvalue); |
121 | - } |
|
122 | - } |
|
123 | - } |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | self::existRole(self::$model); |
151 | 151 | |
152 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
152 | + foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
153 | 153 | $r = self::replaceRegex($r); |
154 | 154 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
155 | 155 | } |
@@ -5,10 +5,10 @@ discard block |
||
5 | 5 | use HnrAzevedo\Validator\Rules; |
6 | 6 | use Exception; |
7 | 7 | |
8 | -Class Validator{ |
|
8 | +Class Validator { |
|
9 | 9 | use Check; |
10 | 10 | |
11 | - public static function add(object $model,callable $return): void |
|
11 | + public static function add(object $model, callable $return): void |
|
12 | 12 | { |
13 | 13 | self::$model = get_class($model); |
14 | 14 | self::$validators[self::$model] = $return($Rules = new Rules($model)); |
@@ -16,35 +16,35 @@ discard block |
||
16 | 16 | |
17 | 17 | private static function existData() |
18 | 18 | { |
19 | - if(!array_key_exists('data', self::$data)){ |
|
19 | + if (!array_key_exists('data', self::$data)) { |
|
20 | 20 | throw new Exception('Informações cruciais não foram recebidas.'); |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | private static function jsonData() |
25 | 25 | { |
26 | - if(json_decode(self::$data['data']) === null){ |
|
26 | + if (json_decode(self::$data['data'])===null) { |
|
27 | 27 | throw new Exception('O servidor recebeu as informações no formato esperado.'); |
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | 31 | private static function hasProvider() |
32 | 32 | { |
33 | - if(!array_key_exists('provider',self::$data)){ |
|
33 | + if (!array_key_exists('provider', self::$data)) { |
|
34 | 34 | throw new Exception('O servidor não recebeu o ID do formulário.'); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | 38 | private static function hasRole() |
39 | 39 | { |
40 | - if(!array_key_exists('role',self::$data)){ |
|
40 | + if (!array_key_exists('role', self::$data)) { |
|
41 | 41 | throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.'); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | private static function getClass(string $class) |
46 | 46 | { |
47 | - if(!class_exists($class)){ |
|
47 | + if (!class_exists($class)) { |
|
48 | 48 | throw new Exception("Form ID {$class} inválido."); |
49 | 49 | } |
50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | private static function existRole($rules) |
57 | 57 | { |
58 | - if(empty(self::$validators[$rules]->getRules(self::$data['role']))){ |
|
58 | + if (empty(self::$validators[$rules]->getRules(self::$data['role']))) { |
|
59 | 59 | throw new Exception('Não existe regras para validar este formulário.'); |
60 | 60 | } |
61 | 61 | } |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | |
81 | 81 | self::existRole(self::$model); |
82 | 82 | |
83 | - foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
84 | - if(@$value['required'] === true){ |
|
83 | + foreach ((self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) { |
|
84 | + if (@$value['required']===true) { |
|
85 | 85 | self::$required[$key] = $value; |
86 | 86 | } |
87 | 87 | } |
@@ -97,27 +97,27 @@ discard block |
||
97 | 97 | |
98 | 98 | public static function checkErrors(): bool |
99 | 99 | { |
100 | - return (count(self::$errors) === 0); |
|
100 | + return (count(self::$errors)===0); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public static function validate() |
104 | 104 | { |
105 | - foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
|
105 | + foreach ((self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) { |
|
106 | 106 | |
107 | 107 | foreach (json_decode(self::$data['data']) as $keyy => $valuee) { |
108 | 108 | |
109 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){ |
|
109 | + if (!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])))) { |
|
110 | 110 | throw new Exception("O campo '{$keyy}' não é esperado para está operação."); |
111 | 111 | } |
112 | 112 | |
113 | - if($keyy===$key){ |
|
113 | + if ($keyy===$key) { |
|
114 | 114 | |
115 | 115 | unset(self::$required[$key]); |
116 | 116 | |
117 | 117 | foreach ($value as $subkey => $subvalue) { |
118 | 118 | $function = "check".ucfirst($subkey); |
119 | 119 | self::testMethod($function); |
120 | - self::$function($keyy,$subvalue); |
|
120 | + self::$function($keyy, $subvalue); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | public static function testMethod($method) |
133 | 133 | { |
134 | - if(!method_exists(static::class, $method)){ |
|
134 | + if (!method_exists(static::class, $method)) { |
|
135 | 135 | throw new Exception("{$method} não é uma validação válida."); |
136 | 136 | } |
137 | 137 | } |
@@ -149,18 +149,18 @@ discard block |
||
149 | 149 | |
150 | 150 | self::existRole(self::$model); |
151 | 151 | |
152 | - foreach ( self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
152 | + foreach (self::$validators[self::$model]->getRules($request['role']) as $field => $r) { |
|
153 | 153 | $r = self::replaceRegex($r); |
154 | 154 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
155 | 155 | } |
156 | 156 | |
157 | - return '{'.substr($response,0,-1).'}'; |
|
157 | + return '{'.substr($response, 0, -1).'}'; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | private static function replaceRegex(array $rules): array |
161 | 161 | { |
162 | - if(array_key_exists('regex',$rules)){ |
|
163 | - $rules['regex'] = substr($rules['regex'],1,-2); |
|
162 | + if (array_key_exists('regex', $rules)) { |
|
163 | + $rules['regex'] = substr($rules['regex'], 1, -2); |
|
164 | 164 | } |
165 | 165 | return $rules; |
166 | 166 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | 'password' => 123456, |
13 | 13 | 'password2' => 123456, |
14 | 14 | 'phones' => json_encode([ |
15 | - '949164770','949164771','949164772' |
|
15 | + '949164770', '949164771', '949164772' |
|
16 | 16 | ]), |
17 | 17 | 'birth' => '28/09/1996' |
18 | 18 | ]), |
@@ -20,16 +20,16 @@ discard block |
||
20 | 20 | 'role' => 'login' |
21 | 21 | ]; |
22 | 22 | |
23 | -try{ |
|
23 | +try { |
|
24 | 24 | |
25 | 25 | /* Checks whether the passed data is valid for the selected function */ |
26 | 26 | $valid = Validator::execute($data); |
27 | 27 | |
28 | - if(!$valid){ |
|
28 | + if (!$valid) { |
|
29 | 29 | $errors = []; |
30 | - foreach(Validator::getErrors() as $err => $message){ |
|
30 | + foreach (Validator::getErrors() as $err => $message) { |
|
31 | 31 | $errors[] = [ |
32 | - 'input' => array_keys($message)[0], // Return name input error |
|
32 | + 'input' => array_keys($message)[0], // Return name input error |
|
33 | 33 | 'message' => $message[array_keys($message)[0]] // Return message error |
34 | 34 | ]; |
35 | 35 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | var_dump($json); |
42 | 42 | |
43 | -}catch(Exception $er){ |
|
43 | +}catch (Exception $er) { |
|
44 | 44 | |
45 | 45 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
46 | 46 |
@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | var_dump($json); |
42 | 42 | |
43 | -}catch(Exception $er){ |
|
43 | +} catch(Exception $er){ |
|
44 | 44 | |
45 | 45 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
46 | 46 |