Passed
Branch master (53c825)
by Henri
21:29
created
examples/Validations/User.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@
 block discarded – undo
9 9
 
10 10
         Validator::add($this, function(Rules $rules){
11 11
             $rules->setAction('login')
12
-                  ->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true])
13
-                  ->addField('password',['index'=>2,'minlength'=>6,'maxlength'=>20,'required'=>true])
14
-				  ->addField('remember',['index'=>3,'minlength'=>2,'maxlength'=>2,'required'=>false]);
12
+                    ->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true])
13
+                    ->addField('password',['index'=>2,'minlength'=>6,'maxlength'=>20,'required'=>true])
14
+                    ->addField('remember',['index'=>3,'minlength'=>2,'maxlength'=>2,'required'=>false]);
15 15
 
16
-			return $rules;
16
+            return $rules;
17 17
         });
18 18
 
19 19
         return $this;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2,16 +2,16 @@
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Validator;
4 4
 
5
-Class User{
5
+Class User {
6 6
 
7 7
     public function __construct()
8 8
     {
9 9
 
10
-        Validator::add($this, function(Rules $rules){
10
+        Validator::add($this, function(Rules $rules) {
11 11
             $rules->setAction('login')
12
-                  ->addField('email',['minlength'=>1,'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/','required'=>true])
13
-                  ->addField('password',['index'=>2,'minlength'=>6,'maxlength'=>20,'required'=>true])
14
-				  ->addField('remember',['index'=>3,'minlength'=>2,'maxlength'=>2,'required'=>false]);
12
+                  ->addField('email', ['minlength'=>1, 'regex'=>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', 'required'=>true])
13
+                  ->addField('password', ['index'=>2, 'minlength'=>6, 'maxlength'=>20, 'required'=>true])
14
+				  ->addField('remember', ['index'=>3, 'minlength'=>2, 'maxlength'=>2, 'required'=>false]);
15 15
 
16 16
 			return $rules;
17 17
         });
Please login to merge, or discard this patch.
examples/index.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 /* NOTE: in case of error an exception is thrown */
9 9
 
10
-try{
10
+try {
11 11
     /* Required format for validation */
12 12
     $data = [
13 13
         'data' => json_encode([
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     /* Transforms validation to Json format to be validated on the client if desired */
25 25
     $json = Validator::toJson($data);
26 26
 
27
-}catch(Exception $er){
27
+}catch (Exception $er) {
28 28
 
29 29
     die($er->getCode().'  -  '.$er->getMessage());
30 30
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
     /* Transforms validation to Json format to be validated on the client if desired */
25 25
     $json = Validator::toJson($data);
26 26
 
27
-}catch(Exception $er){
27
+} catch(Exception $er){
28 28
 
29 29
     die($er->getCode().'  -  '.$er->getMessage());
30 30
 
Please login to merge, or discard this patch.
src/Rules.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,30 +11,30 @@
 block discarded – undo
11 11
 
12 12
     public function __construct(object $model)
13 13
     {
14
-	    $this->form['model'] = ucfirst(get_class($model));
15
-	}
14
+        $this->form['model'] = ucfirst(get_class($model));
15
+    }
16 16
 
17 17
     public function setAction(string $action): Rules
18 18
     {
19
-	    $this->action = $action;
20
-	    return $this;
21
-	}
19
+        $this->action = $action;
20
+        return $this;
21
+    }
22 22
 
23 23
     public function addField(string $field, array $test): Rules
24 24
     {
25
-	    if(empty($this->action)){
25
+        if(empty($this->action)){
26 26
             throw new Exception("Form action not registered.");
27 27
         }
28 28
 
29
-	    if(empty($this->form[$this->action][$field])){
29
+        if(empty($this->form[$this->action][$field])){
30 30
             $this->form[$this->action][$field] = $test;
31 31
         }
32 32
 
33
-	    return $this;
34
-  	}
33
+        return $this;
34
+        }
35 35
 
36 36
     public function getRules(string $action): array
37 37
     {
38
-		return (array_key_exists($action, $this->form)) ? $this->form[$action] : null;
39
-	}
38
+        return (array_key_exists($action, $this->form)) ? $this->form[$action] : null;
39
+    }
40 40
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-Class Rules{
7
+Class Rules {
8 8
     private string $action;
9 9
 
10 10
     private array $form = array();
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 
23 23
     public function addField(string $field, array $test): Rules
24 24
     {
25
-	    if(empty($this->action)){
25
+	    if (empty($this->action)) {
26 26
             throw new Exception("Form action not registered.");
27 27
         }
28 28
 
29
-	    if(empty($this->form[$this->action][$field])){
29
+	    if (empty($this->form[$this->action][$field])) {
30 30
             $this->form[$this->action][$field] = $test;
31 31
         }
32 32
 
Please login to merge, or discard this patch.
src/Validator.php 3 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@  discard block
 block discarded – undo
12 12
     public static function add(object $model,object $return): void
13 13
     {
14 14
         self::$validators[get_class($model)] = $return($Rules = new Rules($model));
15
-	}
15
+    }
16 16
 
17 17
     public static function execute(array $datas): bool
18 18
     {
19
-		$field_error = null;
19
+        $field_error = null;
20 20
 
21
-		if(!array_key_exists('data', $datas)){
21
+        if(!array_key_exists('data', $datas)){
22 22
             throw new Exception('Informações cruciais não foram recebidas.');
23 23
         }
24 24
 
25
-		if(gettype($datas['data']) != 'string' || @json_decode($datas['data']) === null){
25
+        if(gettype($datas['data']) != 'string' || @json_decode($datas['data']) === null){
26 26
             throw new Exception('O servidor recebeu as informações no formato esperado.');
27 27
         }
28 28
 			    
29
-		if(!array_key_exists('provider',$datas) || is_null($datas['provider'])){
29
+        if(!array_key_exists('provider',$datas) || is_null($datas['provider'])){
30 30
             throw new Exception('O servidor não recebeu o ID do formulário.');
31 31
         }
32 32
 			    
33
-		if(!array_key_exists('role',$datas) || is_null($datas['role'])){
33
+        if(!array_key_exists('role',$datas) || is_null($datas['role'])){
34 34
             throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.');
35 35
         }
36 36
 
@@ -46,59 +46,59 @@  discard block
 block discarded – undo
46 46
 
47 47
         $class = 'HnrAzevedo\\Validator\\'.ucfirst($datas['provider']);
48 48
 
49
-		if(!class_exists($class)){
49
+        if(!class_exists($class)){
50 50
             throw new Exception("Form ID {$class} inválido.");
51 51
         }
52 52
 
53 53
         $rules = new $class();
54 54
             
55
-		if(get_class(self::$validators[get_class($rules)]) !== 'HnrAzevedo\Validator\Rules'){
55
+        if(get_class(self::$validators[get_class($rules)]) !== 'HnrAzevedo\Validator\Rules'){
56 56
             throw new Exception('Ocorreu algum erro e o servidor não pode identificar o responsável por validar o formulário submetido.');
57 57
         }
58 58
 
59
-		if(empty(self::$validators[get_class($rules)]->getRules($role))){
59
+        if(empty(self::$validators[get_class($rules)]->getRules($role))){
60 60
             throw new Exception('Não existe regras para validar este formulário.');
61 61
         }
62 62
 
63
-		$validators = self::$validators[get_class($rules)]->getRules($role);
63
+        $validators = self::$validators[get_class($rules)]->getRules($role);
64 64
 
65 65
         $tests = 0;
66 66
             
67
-		foreach ($validators as $key => $value) {
68
-		    $tests = (array_key_exists('required',$value) and $value['required']===true) ? $tests+1 : $tests;
69
-		}
67
+        foreach ($validators as $key => $value) {
68
+            $tests = (array_key_exists('required',$value) and $value['required']===true) ? $tests+1 : $tests;
69
+        }
70 70
 
71
-		$testeds = 0;
71
+        $testeds = 0;
72 72
 
73
-		foreach ($validators as $key => $value) {
73
+        foreach ($validators as $key => $value) {
74 74
 
75
-			foreach ($data as $keyy => $valuee) {
75
+            foreach ($data as $keyy => $valuee) {
76 76
 
77 77
                 $v = $valuee;
78 78
                     
79
-				if(is_array($valuee)){
80
-					$v = null;
81
-					foreach ($valuee as $vvv) {
82
-						$v .= $vvv;
83
-					}
79
+                if(is_array($valuee)){
80
+                    $v = null;
81
+                    foreach ($valuee as $vvv) {
82
+                        $v .= $vvv;
83
+                    }
84 84
                 }
85 85
                     
86
-				$valuee = $v;
86
+                $valuee = $v;
87 87
 
88
-				if(!array_key_exists($keyy, $validators)){
88
+                if(!array_key_exists($keyy, $validators)){
89 89
                     throw new Exception("O campo '{$keyy}' não é esperado para está operação.");
90 90
                 }
91 91
 
92
-				if($keyy===$key){
92
+                if($keyy===$key){
93 93
 
94 94
                     $testeds++;
95 95
                         
96
-					foreach ($value as $subkey => $subvalue) {
96
+                    foreach ($value as $subkey => $subvalue) {
97 97
 
98
-						$field_error = $key;
98
+                        $field_error = $key;
99 99
 
100
-						switch ($subkey) {
101
-							case 'minlength':
100
+                        switch ($subkey) {
101
+                            case 'minlength':
102 102
                                 if(array_key_exists('required', $value)){
103 103
                                     if($value['required'] or strlen($valuee)!==0){
104 104
                                         if(strlen($valuee)===0){
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
                                         }
129 129
                                     }
130 130
                                 }
131
-    						    break;
131
+                                break;
132 132
 
133
-							case 'maxlength':
133
+                            case 'maxlength':
134 134
                                 if(array_key_exists('required', $value)){
135 135
                                     if($value['required'] or strlen($valuee)!==0){
136 136
                                         if(strlen($valuee)>(int)$subvalue){
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                                 }
141 141
                                 break;
142 142
 
143
-							case 'regex':
143
+                            case 'regex':
144 144
                                 if(array_key_exists('required', $value)){
145 145
                                     if($value['required'] or strlen($valuee)!==0){
146 146
                                         if(!@preg_match($subvalue,$valuee)){
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                                 }
151 151
                                 break;
152 152
 
153
-							case 'equals':
153
+                            case 'equals':
154 154
                                 $equals = false;
155 155
                                 foreach ($data as $ke => $sub) {
156 156
                                     if($ke===$subvalue){
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
                                     throw new Exception("O servidor não encontrou a informação '{$subvalue}' para ser comparada a '{$key}'.",1);
164 164
                                 }
165 165
                                 break;
166
-	    				}
167
-					}
168
-				}
169
-			}
166
+                        }
167
+                    }
168
+                }
169
+            }
170 170
         }
171 171
             
172
-		if($tests>$testeds){
172
+        if($tests>$testeds){
173 173
             throw new Exception('Alguma informação necessária não pode ser validada.');
174 174
         }
175 175
 				
176
-		return true;
177
-	}
176
+        return true;
177
+    }
178 178
 
179 179
     public static function toJson(array $request): string
180 180
     {
@@ -188,38 +188,38 @@  discard block
 block discarded – undo
188 188
 
189 189
         $class = 'HnrAzevedo\\Validator\\'.ucfirst($request['provider']);
190 190
 
191
-		if(!class_exists($class)){
191
+        if(!class_exists($class)){
192 192
             throw new Exception("Form ID {$class} inválido.");
193 193
         }
194 194
 
195
-		$model = new $class();
195
+        $model = new $class();
196 196
 
197
-		if(get_class(self::$validators[get_class($model)]) !== 'HnrAzevedo\Validator\Rules'){
197
+        if(get_class(self::$validators[get_class($model)]) !== 'HnrAzevedo\Validator\Rules'){
198 198
             throw new Exception('Ocorreu algum erro e o servidor não pode identificar o responsável por validar o formulário submetido.');
199 199
         }
200 200
 		
201
-		if(empty(self::$validators[get_class($model)]->getRules($request['role']))){
201
+        if(empty(self::$validators[get_class($model)]->getRules($request['role']))){
202 202
             throw new Exception('Formulário desativado: Não existem regras para validar este formulário.');
203 203
         }
204 204
 		
205
-		$validators = self::$validators[get_class($model)]->getRules($request['role']);
205
+        $validators = self::$validators[get_class($model)]->getRules($request['role']);
206 206
 
207 207
         /* For function to validate information in javascript */
208 208
         $response = '{';
209
-		foreach ($validators as $field => $rules) {
210
-			$response .= $field.':{';
211
-			foreach(array_reverse($rules) as $rule => $value){
212
-				$value = (gettype($value)==='string') ? '\''.$value.'\'' : $value;
213
-				if(gettype($value)==='boolean'){
209
+        foreach ($validators as $field => $rules) {
210
+            $response .= $field.':{';
211
+            foreach(array_reverse($rules) as $rule => $value){
212
+                $value = (gettype($value)==='string') ? '\''.$value.'\'' : $value;
213
+                if(gettype($value)==='boolean'){
214 214
                     $value = ($value) ? 'true' : 'false';
215 215
                 }
216
-			    $value = ($rule=='regex') ? str_replace('\\','\\\\','\''.substr($value,2,strlen($value)-4).'\'') : $value;
217
-				$response .= $rule.':'.$value.',';
218
-			}
219
-			$response .='},';
216
+                $value = ($rule=='regex') ? str_replace('\\','\\\\','\''.substr($value,2,strlen($value)-4).'\'') : $value;
217
+                $response .= $rule.':'.$value.',';
218
+            }
219
+            $response .='},';
220 220
         }
221 221
 
222 222
         $response = substr(str_replace(',}','}',$response),0,-1).'}';
223
-		return $response;
224
-	}
223
+        return $response;
224
+    }
225 225
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
 use HnrAzevedo\Validator\Rules;
6 6
 use Exception;
7 7
 
8
-Class Validator{
8
+Class Validator {
9 9
     
10 10
     private static array $validators = array();
11 11
 
12
-    public static function add(object $model,object $return): void
12
+    public static function add(object $model, object $return): void
13 13
     {
14 14
         self::$validators[get_class($model)] = $return($Rules = new Rules($model));
15 15
 	}
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
     {
19 19
 		$field_error = null;
20 20
 
21
-		if(!array_key_exists('data', $datas)){
21
+		if (!array_key_exists('data', $datas)) {
22 22
             throw new Exception('Informações cruciais não foram recebidas.');
23 23
         }
24 24
 
25
-		if(gettype($datas['data']) != 'string' || @json_decode($datas['data']) === null){
25
+		if (gettype($datas['data'])!='string' || @json_decode($datas['data'])===null) {
26 26
             throw new Exception('O servidor recebeu as informações no formato esperado.');
27 27
         }
28 28
 			    
29
-		if(!array_key_exists('provider',$datas) || is_null($datas['provider'])){
29
+		if (!array_key_exists('provider', $datas) || is_null($datas['provider'])) {
30 30
             throw new Exception('O servidor não recebeu o ID do formulário.');
31 31
         }
32 32
 			    
33
-		if(!array_key_exists('role',$datas) || is_null($datas['role'])){
33
+		if (!array_key_exists('role', $datas) || is_null($datas['role'])) {
34 34
             throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.');
35 35
         }
36 36
 
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
40 40
             
41 41
         $file = (VALIDATOR_CONFIG['path'].ucfirst($datas['provider']).'.php');
42 42
 
43
-        if(file_exists($file)){
43
+        if (file_exists($file)) {
44 44
             require_once($file);
45 45
         }
46 46
 
47 47
         $class = 'HnrAzevedo\\Validator\\'.ucfirst($datas['provider']);
48 48
 
49
-		if(!class_exists($class)){
49
+		if (!class_exists($class)) {
50 50
             throw new Exception("Form ID {$class} inválido.");
51 51
         }
52 52
 
53 53
         $rules = new $class();
54 54
             
55
-		if(get_class(self::$validators[get_class($rules)]) !== 'HnrAzevedo\Validator\Rules'){
55
+		if (get_class(self::$validators[get_class($rules)])!=='HnrAzevedo\Validator\Rules') {
56 56
             throw new Exception('Ocorreu algum erro e o servidor não pode identificar o responsável por validar o formulário submetido.');
57 57
         }
58 58
 
59
-		if(empty(self::$validators[get_class($rules)]->getRules($role))){
59
+		if (empty(self::$validators[get_class($rules)]->getRules($role))) {
60 60
             throw new Exception('Não existe regras para validar este formulário.');
61 61
         }
62 62
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         $tests = 0;
66 66
             
67 67
 		foreach ($validators as $key => $value) {
68
-		    $tests = (array_key_exists('required',$value) and $value['required']===true) ? $tests+1 : $tests;
68
+		    $tests = (array_key_exists('required', $value) and $value['required']===true) ? $tests+1 : $tests;
69 69
 		}
70 70
 
71 71
 		$testeds = 0;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
                 $v = $valuee;
78 78
                     
79
-				if(is_array($valuee)){
79
+				if (is_array($valuee)) {
80 80
 					$v = null;
81 81
 					foreach ($valuee as $vvv) {
82 82
 						$v .= $vvv;
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
                     
86 86
 				$valuee = $v;
87 87
 
88
-				if(!array_key_exists($keyy, $validators)){
88
+				if (!array_key_exists($keyy, $validators)) {
89 89
                     throw new Exception("O campo '{$keyy}' não é esperado para está operação.");
90 90
                 }
91 91
 
92
-				if($keyy===$key){
92
+				if ($keyy===$key) {
93 93
 
94 94
                     $testeds++;
95 95
                         
@@ -99,30 +99,30 @@  discard block
 block discarded – undo
99 99
 
100 100
 						switch ($subkey) {
101 101
 							case 'minlength':
102
-                                if(array_key_exists('required', $value)){
103
-                                    if($value['required'] or strlen($valuee)!==0){
104
-                                        if(strlen($valuee)===0){
105
-                                            throw new Exception("O campo '{$key}' é obrigatório.",1);
102
+                                if (array_key_exists('required', $value)) {
103
+                                    if ($value['required'] or strlen($valuee)!==0) {
104
+                                        if (strlen($valuee)===0) {
105
+                                            throw new Exception("O campo '{$key}' é obrigatório.", 1);
106 106
                                         }
107 107
                                          
108
-                                        if(strlen($valuee) < (int) $subvalue){
109
-                                            throw new Exception("{$key} não atingiu o mínimo de caracteres esperado.",1);
108
+                                        if (strlen($valuee)<(int) $subvalue) {
109
+                                            throw new Exception("{$key} não atingiu o mínimo de caracteres esperado.", 1);
110 110
                                         }
111 111
                                     }
112 112
                                 }
113 113
                                 break;
114 114
 
115 115
                             case 'type':
116
-                                if(array_key_exists('required', $value)){
117
-                                    if($value['required'] or strlen($valuee)!==0){
116
+                                if (array_key_exists('required', $value)) {
117
+                                    if ($value['required'] or strlen($valuee)!==0) {
118 118
                                         switch ($subvalue) {
119 119
                                             case 'date':
120 120
                                                 $date = explode('/', $valuee);
121
-                                                if(count($date) != 3){
122
-                                                    throw new Exception('Data inválida.',1);
121
+                                                if (count($date)!=3) {
122
+                                                    throw new Exception('Data inválida.', 1);
123 123
                                                 }
124
-                                                if(!@checkdate($date[1],$date[0],$date[2])){
125
-                                                    throw new Exception('Data inválida.',1);
124
+                                                if (!@checkdate($date[1], $date[0], $date[2])) {
125
+                                                    throw new Exception('Data inválida.', 1);
126 126
                                                 }
127 127
                                                 break;
128 128
                                         }
@@ -131,20 +131,20 @@  discard block
 block discarded – undo
131 131
     						    break;
132 132
 
133 133
 							case 'maxlength':
134
-                                if(array_key_exists('required', $value)){
135
-                                    if($value['required'] or strlen($valuee)!==0){
136
-                                        if(strlen($valuee)>(int)$subvalue){
137
-                                            throw new Exception("{$key} ultrapassou o limite de caracteres permitidos.",1);
134
+                                if (array_key_exists('required', $value)) {
135
+                                    if ($value['required'] or strlen($valuee)!==0) {
136
+                                        if (strlen($valuee)>(int) $subvalue) {
137
+                                            throw new Exception("{$key} ultrapassou o limite de caracteres permitidos.", 1);
138 138
                                         }
139 139
                                     }
140 140
                                 }
141 141
                                 break;
142 142
 
143 143
 							case 'regex':
144
-                                if(array_key_exists('required', $value)){
145
-                                    if($value['required'] or strlen($valuee)!==0){
146
-                                        if(!@preg_match($subvalue,$valuee)){
147
-                                            throw new Exception("{$key} inválido(a).",1);
144
+                                if (array_key_exists('required', $value)) {
145
+                                    if ($value['required'] or strlen($valuee)!==0) {
146
+                                        if (!@preg_match($subvalue, $valuee)) {
147
+                                            throw new Exception("{$key} inválido(a).", 1);
148 148
                                         }
149 149
                                     }
150 150
                                 }
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 							case 'equals':
154 154
                                 $equals = false;
155 155
                                 foreach ($data as $ke => $sub) {
156
-                                    if($ke===$subvalue){
157
-                                        $equals=true;
158
-                                        if($valuee!==$sub)
159
-                                            throw new \Exception(ucfirst($key).' está diferente de '.ucfirst($ke),1);
156
+                                    if ($ke===$subvalue) {
157
+                                        $equals = true;
158
+                                        if ($valuee!==$sub)
159
+                                            throw new \Exception(ucfirst($key).' está diferente de '.ucfirst($ke), 1);
160 160
                                     }
161 161
                                 }
162
-                                if(!$equals){
163
-                                    throw new Exception("O servidor não encontrou a informação '{$subvalue}' para ser comparada a '{$key}'.",1);
162
+                                if (!$equals) {
163
+                                    throw new Exception("O servidor não encontrou a informação '{$subvalue}' para ser comparada a '{$key}'.", 1);
164 164
                                 }
165 165
                                 break;
166 166
 	    				}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			}
170 170
         }
171 171
             
172
-		if($tests>$testeds){
172
+		if ($tests>$testeds) {
173 173
             throw new Exception('Alguma informação necessária não pode ser validada.');
174 174
         }
175 175
 				
@@ -181,24 +181,24 @@  discard block
 block discarded – undo
181 181
         $file = (VALIDATOR_CONFIG['path'].ucfirst($request['provider']).'.php');
182 182
         $file = __DIR__.'/../../../../'.$file;
183 183
 
184
-        if(file_exists($file)){
184
+        if (file_exists($file)) {
185 185
             require_once($file);
186 186
         }
187 187
 
188 188
 
189 189
         $class = 'HnrAzevedo\\Validator\\'.ucfirst($request['provider']);
190 190
 
191
-		if(!class_exists($class)){
191
+		if (!class_exists($class)) {
192 192
             throw new Exception("Form ID {$class} inválido.");
193 193
         }
194 194
 
195 195
 		$model = new $class();
196 196
 
197
-		if(get_class(self::$validators[get_class($model)]) !== 'HnrAzevedo\Validator\Rules'){
197
+		if (get_class(self::$validators[get_class($model)])!=='HnrAzevedo\Validator\Rules') {
198 198
             throw new Exception('Ocorreu algum erro e o servidor não pode identificar o responsável por validar o formulário submetido.');
199 199
         }
200 200
 		
201
-		if(empty(self::$validators[get_class($model)]->getRules($request['role']))){
201
+		if (empty(self::$validators[get_class($model)]->getRules($request['role']))) {
202 202
             throw new Exception('Formulário desativado: Não existem regras para validar este formulário.');
203 203
         }
204 204
 		
@@ -208,18 +208,18 @@  discard block
 block discarded – undo
208 208
         $response = '{';
209 209
 		foreach ($validators as $field => $rules) {
210 210
 			$response .= $field.':{';
211
-			foreach(array_reverse($rules) as $rule => $value){
211
+			foreach (array_reverse($rules) as $rule => $value) {
212 212
 				$value = (gettype($value)==='string') ? '\''.$value.'\'' : $value;
213
-				if(gettype($value)==='boolean'){
213
+				if (gettype($value)==='boolean') {
214 214
                     $value = ($value) ? 'true' : 'false';
215 215
                 }
216
-			    $value = ($rule=='regex') ? str_replace('\\','\\\\','\''.substr($value,2,strlen($value)-4).'\'') : $value;
216
+			    $value = ($rule=='regex') ? str_replace('\\', '\\\\', '\''.substr($value, 2, strlen($value)-4).'\'') : $value;
217 217
 				$response .= $rule.':'.$value.',';
218 218
 			}
219
-			$response .='},';
219
+			$response .= '},';
220 220
         }
221 221
 
222
-        $response = substr(str_replace(',}','}',$response),0,-1).'}';
222
+        $response = substr(str_replace(',}', '}', $response), 0, -1).'}';
223 223
 		return $response;
224 224
 	}
225 225
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -155,8 +155,9 @@
 block discarded – undo
155 155
                                 foreach ($data as $ke => $sub) {
156 156
                                     if($ke===$subvalue){
157 157
                                         $equals=true;
158
-                                        if($valuee!==$sub)
159
-                                            throw new \Exception(ucfirst($key).' está diferente de '.ucfirst($ke),1);
158
+                                        if($valuee!==$sub) {
159
+                                                                                    throw new \Exception(ucfirst($key).' está diferente de '.ucfirst($ke),1);
160
+                                        }
160 161
                                     }
161 162
                                 }
162 163
                                 if(!$equals){
Please login to merge, or discard this patch.