Passed
Branch master (319c57)
by Henri
04:02 queued 02:38
created
src/ExtraCheck.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 
15 15
     protected function checkRequireds(): void
16 16
     {
17
-        if(count(self::getInstance()->required) > 0){
17
+        if (count(self::getInstance()->required)>0) {
18 18
             self::getInstance()->errors[] = [
19
-                'As seguintes informações não poderam ser validadas: '.implode(', ',array_keys(self::getInstance()->required))
19
+                'As seguintes informações não poderam ser validadas: '.implode(', ', array_keys(self::getInstance()->required))
20 20
             ];
21 21
         }
22 22
     }
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public function validateDate($date, $format = 'Y-m-d H:i:s')
25 25
     {
26 26
         $d = \DateTime::createFromFormat($format, $date);
27
-        return $d && $d->format($format) == $date;
27
+        return $d && $d->format($format)==$date;
28 28
     }
29 29
 
30 30
     protected function checkRequired(string $param): bool
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 
38 38
     protected function toNext(string $param, $value): bool
39 39
     {
40
-        return (self::getInstance()->checkRequired($param) || strlen($value > 0));
40
+        return (self::getInstance()->checkRequired($param) || strlen($value>0));
41 41
     }
42 42
 
43 43
     protected function testArray(string $param, $value): ?array
44 44
     {
45
-        if(!is_array($value)){
45
+        if (!is_array($value)) {
46 46
             self::getInstance()->errors[] = [
47 47
                 $param => 'Era esperado uma informação em formato array para está informação'
48 48
             ];
Please login to merge, or discard this patch.
src/Check.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
 
9 9
     protected function checkMinlength(string $param, $value): void
10 10
     {
11
-        if(self::getInstance()->toNext($param, $value)){    
11
+        if (self::getInstance()->toNext($param, $value)) {    
12 12
             
13 13
             $realval = (is_array(self::getInstance()->data[$param])) ? self::getInstance()->data[$param] : [self::getInstance()->data[$param]];
14 14
 
15
-            foreach($realval as $val){
16
-                if(strlen($val) === 0) {
15
+            foreach ($realval as $val) {
16
+                if (strlen($val)===0) {
17 17
                     self::getInstance()->errors[] = [
18 18
                         $param => 'é obrigatório'
19 19
                     ];
20 20
                     continue;
21 21
                 }
22
-                if($value > strlen($val)) {
22
+                if ($value>strlen($val)) {
23 23
                     self::getInstance()->errors[] = [
24 24
                         $param => 'não atingiu o mínimo de caracteres esperado'
25 25
                     ];
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 
31 31
     protected function checkRegex(string $param, $value): void
32 32
     {
33
-        if(self::getInstance()->toNext($param, $value)){
33
+        if (self::getInstance()->toNext($param, $value)) {
34 34
 
35 35
             $realval = (is_array(self::getInstance()->data[$param])) ? self::getInstance()->data[$param] : [self::getInstance()->data[$param]];
36 36
 
37
-            foreach($realval as $val){
37
+            foreach ($realval as $val) {
38 38
 
39
-                if(!preg_match(self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])[$param]['regex'], $val)){
39
+                if (!preg_match(self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])[$param]['regex'], $val)) {
40 40
                     self::getInstance()->errors[] = [
41 41
                         $param => 'inválido(a)'
42 42
                     ];
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 
49 49
     protected function checkMincount(string $param, $value): void
50 50
     {
51
-        if(self::getInstance()->toNext($param, $value)){
51
+        if (self::getInstance()->toNext($param, $value)) {
52 52
             $array = self::getInstance()->testArray($param, self::getInstance()->data[$param]);
53
-            if(count($array) < $value){
53
+            if (count($array)<$value) {
54 54
                 self::getInstance()->errors[] = [
55 55
                     $param => 'não atingiu o mínimo esperado'
56 56
                 ];
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 
61 61
     protected function checkMaxcount(string $param, $value): void
62 62
     {
63
-        if(self::getInstance()->toNext($param, $value)){
63
+        if (self::getInstance()->toNext($param, $value)) {
64 64
             $array = self::getInstance()->testArray($param, self::getInstance()->data[$param]);
65
-            if(count($array) > $value){
65
+            if (count($array)>$value) {
66 66
                 self::getInstance()->errors[] = [
67 67
                     $param => 'ultrapassou o esperado'
68 68
                 ];
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 
73 73
     protected function checkEquals(string $param, $value): void
74 74
     {
75
-        if(self::getInstance()->toNext($param, $value)){
75
+        if (self::getInstance()->toNext($param, $value)) {
76 76
 
77
-            if(!array_key_exists($param, self::getInstance()->data)){
77
+            if (!array_key_exists($param, self::getInstance()->data)) {
78 78
                 self::getInstance()->errors[] = [
79 79
                     $param => "O servidor não encontrou a informação '{$value}' para ser comparada"
80 80
                 ];
81 81
             }
82 82
             
83
-            if(self::getInstance()->data[$param] != self::getInstance()->data[$value]){
83
+            if (self::getInstance()->data[$param]!=self::getInstance()->data[$value]) {
84 84
                 self::getInstance()->errors[] = [
85 85
                     $param => 'está diferente de '.ucfirst($value)
86 86
                 ];
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 
92 92
     protected function checkMaxlength(string $param, $value)
93 93
     {
94
-        if(self::getInstance()->toNext($param, $value)){
94
+        if (self::getInstance()->toNext($param, $value)) {
95 95
 
96 96
             $realval = (is_array(self::getInstance()->data[$param])) ? self::getInstance()->data[$param] : [self::getInstance()->data[$param]];
97 97
 
98
-            foreach($realval as $val){
98
+            foreach ($realval as $val) {
99 99
 
100
-                if($value < strlen($val)) {
100
+                if ($value<strlen($val)) {
101 101
                     self::getInstance()->errors[] = [
102 102
                         $param => 'ultrapassou o máximo de caracteres esperado'
103 103
                     ];
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 
110 110
     protected function checkType(string $param, $value)
111 111
     {
112
-        if(self::getInstance()->toNext($param, $value)){
112
+        if (self::getInstance()->toNext($param, $value)) {
113 113
 
114 114
             switch ($value) {
115 115
                 case 'date':
116
-                    if(!self::getInstance()->validateDate(self::getInstance()->data[$param] , 'd/m/Y')){
116
+                    if (!self::getInstance()->validateDate(self::getInstance()->data[$param], 'd/m/Y')) {
117 117
                         self::getInstance()->errors[] = [
118 118
                             $param => 'não é uma data válida'
119 119
                         ];
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 
126 126
     protected function checkFilter(string $param, $value)
127 127
     {
128
-        if(self::getInstance()->toNext($param, $value)){
128
+        if (self::getInstance()->toNext($param, $value)) {
129 129
 
130
-            if(!filter_var(self::getInstance()->data[$param], $value)){
130
+            if (!filter_var(self::getInstance()->data[$param], $value)) {
131 131
                 self::getInstance()->errors[] = [
132 132
                     $param => 'não passou pela filtragem de dados'
133 133
                 ];
Please login to merge, or discard this patch.
src/Validator.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             self::getInstance()->errors[] = $er->getMessage();
77 77
         }
78 78
         
79
-		return self::checkErrors();
79
+        return self::checkErrors();
80 80
     }
81 81
 
82 82
     public static function checkErrors(): bool
@@ -88,21 +88,21 @@  discard block
 block discarded – undo
88 88
     {
89 89
         foreach ( (self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])) as $key => $value) {
90 90
 
91
-			foreach (self::getInstance()->data as $keyy => $valuee) {
91
+            foreach (self::getInstance()->data as $keyy => $valuee) {
92 92
 
93
-				self::getInstance()->checkExpected($keyy);
93
+                self::getInstance()->checkExpected($keyy);
94 94
 
95
-				if($keyy===$key){
95
+                if($keyy===$key){
96 96
 
97 97
                     unset(self::getInstance()->required[$key]);
98 98
 
99
-					foreach ($value as $subkey => $subvalue) {
99
+                    foreach ($value as $subkey => $subvalue) {
100 100
                         $function = "check".ucfirst($subkey);
101 101
                         self::getInstance()->testMethod($function);
102 102
                         self::getInstance()->$function($keyy, $subvalue);
103
-					}
104
-				}
105
-			}
103
+                    }
104
+                }
105
+            }
106 106
         }
107 107
     }
108 108
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
         self::getInstance()->existRole(self::getInstance()->model);
142 142
 
143
-		foreach ( self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE'])  as $field => $r) {
143
+        foreach ( self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE'])  as $field => $r) {
144 144
             $r = self::getInstance()->replaceRegex($r);
145 145
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
146 146
         }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
         'ROLE'
19 19
     ];
20 20
 
21
-    public static function add(object $model,callable $return): void
21
+    public static function add(object $model, callable $return): void
22 22
     {
23 23
         self::getInstance()->model = get_class($model);
24 24
         self::getInstance()->validators[self::getInstance()->model] = $return(new Rules($model));
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
     private static function getClass(string $class)
28 28
     {
29
-        if(!class_exists($class)){
29
+        if (!class_exists($class)) {
30 30
             throw new \RuntimeException("Form ID {$class} inválido");
31 31
         }
32 32
 
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 
38 38
     private function existRole($rules)
39 39
     {
40
-        if(empty(self::getInstance()->validators[$rules]->getRules(self::getInstance()->data['ROLE']))){
40
+        if (empty(self::getInstance()->validators[$rules]->getRules(self::getInstance()->data['ROLE']))) {
41 41
             throw new \RuntimeException('Não existe regras para validar este formulário');
42 42
         }
43 43
     }
44 44
 
45 45
     public function checkDatas(array $data): void
46 46
     {
47
-        if(!isset($data['PROVIDER']) || !isset($data['ROLE'])){
47
+        if (!isset($data['PROVIDER']) || !isset($data['ROLE'])) {
48 48
             throw new \RuntimeException('The server did not receive the information needed to retrieve the requested validator');
49 49
         }
50 50
     }
51 51
 
52 52
     public static function execute(array $data): bool
53 53
     {
54
-        try{
54
+        try {
55 55
             self::getInstance()->checkDatas($data);
56 56
 
57 57
             self::getInstance()->data = $data;
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
             self::getInstance()->existRole(self::getInstance()->model);
64 64
                 
65
-            foreach ( (self::getInstance()->validators[self::getInstance()->model]->getRules($data['ROLE'])) as $key => $value) {
66
-                if(@$value['required'] === true){
65
+            foreach ((self::getInstance()->validators[self::getInstance()->model]->getRules($data['ROLE'])) as $key => $value) {
66
+                if (@$value['required']===true) {
67 67
                     self::getInstance()->required[$key] = $value;
68 68
                 }
69 69
             }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         
73 73
             self::getInstance()->validate();
74 74
             self::getInstance()->checkRequireds();
75
-        }catch(\Exception $er){
75
+        }catch (\Exception $er) {
76 76
             self::getInstance()->errors[] = $er->getMessage();
77 77
         }
78 78
         
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 
82 82
     public static function checkErrors(): bool
83 83
     {
84
-        return (count(self::getInstance()->errors) === 0);
84
+        return (count(self::getInstance()->errors)===0);
85 85
     }
86 86
     
87 87
     public function validate(): void
88 88
     {
89
-        foreach ( (self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])) as $key => $value) {
89
+        foreach ((self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])) as $key => $value) {
90 90
 
91 91
 			foreach (self::getInstance()->data as $keyy => $valuee) {
92 92
 
93 93
 				self::getInstance()->checkExpected($keyy);
94 94
 
95
-				if($keyy===$key){
95
+				if ($keyy===$key) {
96 96
 
97 97
                     unset(self::getInstance()->required[$key]);
98 98
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
     private function checkExpected(string $keyy): void
110 110
     {
111
-        if(!array_key_exists($keyy, (self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE'])) ) && !in_array($keyy, self::getInstance()->defaultData)){
111
+        if (!array_key_exists($keyy, (self::getInstance()->validators[self::getInstance()->model]->getRules(self::getInstance()->data['ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) {
112 112
             throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação");
113 113
         }
114 114
     }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
     public function testMethod($method)
122 122
     {
123
-        if(!method_exists(static::class, $method)){
123
+        if (!method_exists(static::class, $method)) {
124 124
             throw new \RuntimeException("{$method} não é uma validação válida");
125 125
         }
126 126
     }
@@ -140,17 +140,17 @@  discard block
 block discarded – undo
140 140
 
141 141
         self::getInstance()->existRole(self::getInstance()->model);
142 142
 
143
-		foreach ( self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE'])  as $field => $r) {
143
+		foreach (self::getInstance()->validators[self::getInstance()->model]->getRules($request['ROLE'])  as $field => $r) {
144 144
             $r = self::getInstance()->replaceRegex($r);
145 145
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
146 146
         }
147 147
 
148
-        return '{'.substr($response,0,-1).'}';
148
+        return '{'.substr($response, 0, -1).'}';
149 149
     }
150 150
     
151 151
     private function replaceRegex(array $rules): array
152 152
     {
153
-        if(array_key_exists('regex', $rules)){ 
153
+        if (array_key_exists('regex', $rules)) { 
154 154
             $rules['regex'] = substr($rules['regex'], 1, -2);
155 155
         }
156 156
         return $rules;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
         
73 73
             self::getInstance()->validate();
74 74
             self::getInstance()->checkRequireds();
75
-        }catch(\Exception $er){
75
+        } catch(\Exception $er){
76 76
             self::getInstance()->errors[] = $er->getMessage();
77 77
         }
78 78
         
Please login to merge, or discard this patch.