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