Passed
Push — master ( 08a7b7...dde000 )
by Henri
01:17
created
src/Validator.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
     public static function checkDatas()
69 69
     {
70
-		self::existData();
70
+        self::existData();
71 71
         self::jsonData();
72 72
         self::hasProvider();
73 73
         self::hasRole();
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
         self::$model = get_class(self::getClass('HnrAzevedo\\Validator\\'.ucfirst(self::$data['provider'])));
85 85
 
86
-		self::existRole(self::$model);
86
+        self::existRole(self::$model);
87 87
             
88
-		foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) {
88
+        foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) {
89 89
             if(@$value['required'] === true){
90 90
                 self::$required[$key] = $value;
91 91
             }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         
98 98
         self::check_requireds();
99 99
 				
100
-		return self::check_errors();
100
+        return self::check_errors();
101 101
     }
102 102
 
103 103
     public static function check_errors(): bool
@@ -109,23 +109,23 @@  discard block
 block discarded – undo
109 109
     {
110 110
         foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) {
111 111
 
112
-			foreach (json_decode(self::$data['data']) as $keyy => $valuee) {
112
+            foreach (json_decode(self::$data['data']) as $keyy => $valuee) {
113 113
 
114
-				if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){
114
+                if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){
115 115
                     throw new Exception("O campo '{$keyy}' não é esperado para está operação.");
116 116
                 }
117 117
 
118
-				if($keyy===$key){
118
+                if($keyy===$key){
119 119
 
120 120
                     unset(self::$required[$key]);
121 121
 
122
-					foreach ($value as $subkey => $subvalue) {
122
+                    foreach ($value as $subkey => $subvalue) {
123 123
                         $function = "check_{$subkey}";
124 124
                         self::testMethod($function);
125 125
                         self::$function($keyy,$subvalue);
126
-					}
127
-				}
128
-			}
126
+                    }
127
+                }
128
+            }
129 129
         }
130 130
     }
131 131
 
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 
155 155
         self::existRole(self::$model);
156 156
 
157
-		foreach ( self::$validators[self::$model]->getRules($request['role'])  as $field => $r) {
157
+        foreach ( self::$validators[self::$model]->getRules($request['role'])  as $field => $r) {
158 158
             
159 159
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
160 160
             
161 161
         }
162 162
 
163 163
         return '{'.str_replace('"','',substr($response,0,-1)).'}';
164
-	}
164
+    }
165 165
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@  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
     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,42 +16,42 @@  discard block
 block discarded – undo
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 includeValidations()
46 46
     {
47
-        if( file_exists(VALIDATOR_CONFIG['path'] . ucfirst(self::$data['provider']) . '.php') ){
48
-            require_once(VALIDATOR_CONFIG['path'] . ucfirst(self::$data['provider']) . '.php');
47
+        if (file_exists(VALIDATOR_CONFIG['path'].ucfirst(self::$data['provider']).'.php')) {
48
+            require_once(VALIDATOR_CONFIG['path'].ucfirst(self::$data['provider']).'.php');
49 49
         }
50 50
     }
51 51
 
52 52
     private static function getClass(string $class)
53 53
     {
54
-        if(!class_exists($class)){
54
+        if (!class_exists($class)) {
55 55
             throw new Exception("Form ID {$class} inválido.");
56 56
         }
57 57
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
     private static function existRole($rules)
62 62
     {
63
-        if(empty(self::$validators[$rules]->getRules(self::$data['role']))){
63
+        if (empty(self::$validators[$rules]->getRules(self::$data['role']))) {
64 64
             throw new Exception('Não existe regras para validar este formulário.');
65 65
         }
66 66
     }
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 
86 86
 		self::existRole(self::$model);
87 87
             
88
-		foreach ( (self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) {
89
-            if(@$value['required'] === true){
88
+		foreach ((self::$validators[self::$model]->getRules($datas['role'])) as $key => $value) {
89
+            if (@$value['required']===true) {
90 90
                 self::$required[$key] = $value;
91 91
             }
92 92
         }
@@ -102,27 +102,27 @@  discard block
 block discarded – undo
102 102
 
103 103
     public static function check_errors(): bool
104 104
     {
105
-        return (count(self::$errors) === 0);
105
+        return (count(self::$errors)===0);
106 106
     }
107 107
     
108 108
     public static function validate()
109 109
     {
110
-        foreach ( (self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) {
110
+        foreach ((self::$validators[self::$model]->getRules(self::$data['role'])) as $key => $value) {
111 111
 
112 112
 			foreach (json_decode(self::$data['data']) as $keyy => $valuee) {
113 113
 
114
-				if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])) )){
114
+				if (!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['role'])))) {
115 115
                     throw new Exception("O campo '{$keyy}' não é esperado para está operação.");
116 116
                 }
117 117
 
118
-				if($keyy===$key){
118
+				if ($keyy===$key) {
119 119
 
120 120
                     unset(self::$required[$key]);
121 121
 
122 122
 					foreach ($value as $subkey => $subvalue) {
123 123
                         $function = "check_{$subkey}";
124 124
                         self::testMethod($function);
125
-                        self::$function($keyy,$subvalue);
125
+                        self::$function($keyy, $subvalue);
126 126
 					}
127 127
 				}
128 128
 			}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
     public static function testMethod($method)
138 138
     {
139
-        if(!method_exists(static::class, $method)){
139
+        if (!method_exists(static::class, $method)) {
140 140
             throw new Exception("{$method} não é uma validação válida.");
141 141
         }
142 142
     }
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
 
151 151
         self::includeValidations();
152 152
 
153
-        self::$model = get_class( self::getClass('HnrAzevedo\\Validator\\'.ucfirst($request['provider'])) );
153
+        self::$model = get_class(self::getClass('HnrAzevedo\\Validator\\'.ucfirst($request['provider'])));
154 154
 
155 155
         self::existRole(self::$model);
156 156
 
157
-		foreach ( self::$validators[self::$model]->getRules($request['role'])  as $field => $r) {
157
+		foreach (self::$validators[self::$model]->getRules($request['role'])  as $field => $r) {
158 158
             
159 159
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
160 160
             
161 161
         }
162 162
 
163
-        return '{'.str_replace('"','',substr($response,0,-1)).'}';
163
+        return '{'.str_replace('"', '', substr($response, 0, -1)).'}';
164 164
 	}
165 165
 }
Please login to merge, or discard this patch.