Passed
Branch master (cd9e8c)
by Henri
02:20 queued 01:06
created
examples/Validations/User.php 1 patch
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.
src/Rules.php 1 patch
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.
src/Validator.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     {
71 71
         self::$data = $datas;
72 72
 
73
-		self::existData();
73
+        self::existData();
74 74
         self::jsonData();
75 75
         self::hasProvider();
76 76
         self::hasRole();
@@ -79,23 +79,23 @@  discard block
 block discarded – undo
79 79
 
80 80
         $rules = self::getClass('HnrAzevedo\\Validator\\'.ucfirst(self::$data['provider']));
81 81
 
82
-		self::existRole($rules);
82
+        self::existRole($rules);
83 83
 
84
-		$validators = self::$validators[get_class($rules)]->getRules($datas['role']);
84
+        $validators = self::$validators[get_class($rules)]->getRules($datas['role']);
85 85
 
86 86
         $tests = 0;
87 87
             
88
-		foreach ($validators as $key => $value) {
89
-		    $tests = (@$value['required'] === true ) ? $tests+1 : $tests;
88
+        foreach ($validators as $key => $value) {
89
+            $tests = (@$value['required'] === true ) ? $tests+1 : $tests;
90 90
         }
91 91
 
92
-		$testeds = self::validate($validators);
92
+        $testeds = self::validate($validators);
93 93
             
94
-		if($tests > $testeds){
94
+        if($tests > $testeds){
95 95
             throw new Exception('Alguma informação necessária não pode ser validada.');
96 96
         }
97 97
 				
98
-		return true;
98
+        return true;
99 99
     }
100 100
     
101 101
     public static function validate(array $validators): int
@@ -103,31 +103,31 @@  discard block
 block discarded – undo
103 103
         $validate = 0;
104 104
         foreach ($validators as $key => $value) {
105 105
 
106
-			foreach (json_decode(self::$data['data']) as $keyy => $valuee) {
106
+            foreach (json_decode(self::$data['data']) as $keyy => $valuee) {
107 107
 
108 108
                 $v = $valuee;
109 109
                     
110
-				if(is_array($valuee)){
111
-					$v = null;
112
-					foreach ($valuee as $vvv) {
113
-						$v .= $vvv;
114
-					}
110
+                if(is_array($valuee)){
111
+                    $v = null;
112
+                    foreach ($valuee as $vvv) {
113
+                        $v .= $vvv;
114
+                    }
115 115
                 }
116 116
                     
117
-				$valuee = $v;
117
+                $valuee = $v;
118 118
 
119
-				if(!array_key_exists($keyy, $validators)){
119
+                if(!array_key_exists($keyy, $validators)){
120 120
                     throw new Exception("O campo '{$keyy}' não é esperado para está operação.");
121 121
                 }
122 122
 
123
-				if($keyy===$key){
123
+                if($keyy===$key){
124 124
 
125 125
                     $validate++;
126 126
                         
127
-					foreach ($value as $subkey => $subvalue) {
127
+                    foreach ($value as $subkey => $subvalue) {
128 128
 
129
-						switch ($subkey) {
130
-							case 'minlength':
129
+                        switch ($subkey) {
130
+                            case 'minlength':
131 131
                                 if(array_key_exists('required', $value)){
132 132
                                     if($value['required'] or strlen($valuee)!==0){
133 133
                                         if(strlen($valuee)===0){
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
                                         }
158 158
                                     }
159 159
                                 }
160
-    						    break;
160
+                                break;
161 161
 
162
-							case 'maxlength':
162
+                            case 'maxlength':
163 163
                                 if(array_key_exists('required', $value)){
164 164
                                     if($value['required'] or strlen($valuee)!==0){
165 165
                                         if(strlen($valuee)>(int)$subvalue){
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                                 }
170 170
                                 break;
171 171
 
172
-							case 'regex':
172
+                            case 'regex':
173 173
                                 if(array_key_exists('required', $value)){
174 174
                                     if($value['required'] or strlen($valuee)!==0){
175 175
                                         if(!@preg_match($subvalue,$valuee)){
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
                                 }
180 180
                                 break;
181 181
 
182
-							case 'equals':
182
+                            case 'equals':
183 183
                                 $equals = false;
184 184
                                 foreach (self::$data as $ke => $sub) {
185 185
                                     if($ke===$subvalue){
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
                                     throw new Exception("O servidor não encontrou a informação '{$subvalue}' para ser comparada a '{$key}'.",1);
194 194
                                 }
195 195
                                 break;
196
-	    				}
197
-					}
198
-				}
199
-			}
196
+                        }
197
+                    }
198
+                }
199
+            }
200 200
         }
201 201
         return $validate;
202 202
     }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
         self::existRole($rules);
216 216
 
217
-		foreach ( self::$validators[get_class($rules)]->getRules($request['role'])  as $field => $r) {
217
+        foreach ( self::$validators[get_class($rules)]->getRules($request['role'])  as $field => $r) {
218 218
             
219 219
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
220 220
             
@@ -225,6 +225,6 @@  discard block
 block discarded – undo
225 225
         $response = str_replace('{"','',$response);
226 226
         $response = str_replace('":',':',$response);
227 227
 
228
-		return $response;
229
-	}
228
+        return $response;
229
+    }
230 230
 }
Please login to merge, or discard this patch.