Passed
Push — master ( c44634...5079d8 )
by Henri
08:48 queued 10s
created
src/Validator.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
             
65 65
         self::$model = self::getClass($model);
66 66
 
67
-		self::existRole(self::$model);
67
+        self::existRole(self::$model);
68 68
             
69
-		foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) {
69
+        foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) {
70 70
             if(@$value['required'] === true){
71 71
                 self::$required[$key] = $value;
72 72
             }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         
79 79
         self::checkRequireds();
80 80
 				
81
-		return self::checkErrors();
81
+        return self::checkErrors();
82 82
     }
83 83
 
84 84
     public static function checkErrors(): bool
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
     {
91 91
         foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) {
92 92
 
93
-			foreach (self::$data as $keyy => $valuee) {
93
+            foreach (self::$data as $keyy => $valuee) {
94 94
 
95
-				if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){
95
+                if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){
96 96
                     throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação.");
97 97
                 }
98 98
 
99
-				if($keyy===$key){
99
+                if($keyy===$key){
100 100
 
101 101
                     unset(self::$required[$key]);
102 102
 
103
-					foreach ($value as $subkey => $subvalue) {
103
+                    foreach ($value as $subkey => $subvalue) {
104 104
                         $function = "check".ucfirst($subkey);
105 105
                         self::testMethod($function);
106 106
                         self::$function($keyy,$subvalue);
107
-					}
108
-				}
109
-			}
107
+                    }
108
+                }
109
+            }
110 110
         }
111 111
     }
112 112
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 
138 138
         self::existRole(self::$model);
139 139
 
140
-		foreach ( self::$validators[self::$model]->getRules($request['ROLE'])  as $field => $r) {
140
+        foreach ( self::$validators[self::$model]->getRules($request['ROLE'])  as $field => $r) {
141 141
             $r = self::replaceRegex($r);
142 142
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
143 143
         }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
         return self::$instance;
24 24
     }
25 25
 
26
-    public static function add(object $model,callable $return): void
26
+    public static function add(object $model, callable $return): void
27 27
     {
28 28
         self::$model = get_class($model);
29 29
         self::$validators[self::$model] = $return(new Rules($model));
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
     private static function getClass(string $class)
33 33
     {
34
-        if(!class_exists($class)){
34
+        if (!class_exists($class)) {
35 35
             throw new \RuntimeException("Form ID {$class} inválido.");
36 36
         }
37 37
 
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 
43 43
     private static function existRole($rules)
44 44
     {
45
-        if(empty(self::$validators[$rules]->getRules(self::$data['ROLE']))){
45
+        if (empty(self::$validators[$rules]->getRules(self::$data['ROLE']))) {
46 46
             throw new \RuntimeException('Não existe regras para validar este formulário.');
47 47
         }
48 48
     }
49 49
 
50 50
     public function checkDatas(array $data): void
51 51
     {
52
-        if(!isset($data['PROVIDER']) || !isset($data['ROLE'])){
52
+        if (!isset($data['PROVIDER']) || !isset($data['ROLE'])) {
53 53
             throw new \RuntimeException('The server did not receive the information needed to retrieve the requested validator');
54 54
         }
55 55
     }
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 
67 67
 		self::existRole(self::$model);
68 68
             
69
-		foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) {
70
-            if(@$value['required'] === true){
69
+		foreach ((self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) {
70
+            if (@$value['required']===true) {
71 71
                 self::$required[$key] = $value;
72 72
             }
73 73
         }
@@ -83,27 +83,27 @@  discard block
 block discarded – undo
83 83
 
84 84
     public static function checkErrors(): bool
85 85
     {
86
-        return (count(self::$errors) === 0);
86
+        return (count(self::$errors)===0);
87 87
     }
88 88
     
89 89
     public static function validate(): void
90 90
     {
91
-        foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) {
91
+        foreach ((self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) {
92 92
 
93 93
 			foreach (self::$data as $keyy => $valuee) {
94 94
 
95
-				if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){
95
+				if (!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) {
96 96
                     throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação.");
97 97
                 }
98 98
 
99
-				if($keyy===$key){
99
+				if ($keyy===$key) {
100 100
 
101 101
                     unset(self::$required[$key]);
102 102
 
103 103
 					foreach ($value as $subkey => $subvalue) {
104 104
                         $function = "check".ucfirst($subkey);
105 105
                         self::testMethod($function);
106
-                        self::$function($keyy,$subvalue);
106
+                        self::$function($keyy, $subvalue);
107 107
 					}
108 108
 				}
109 109
 			}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
     public static function testMethod($method)
119 119
     {
120
-        if(!method_exists(static::class, $method)){
120
+        if (!method_exists(static::class, $method)) {
121 121
             throw new \RuntimeException("{$method} não é uma validação válida.");
122 122
         }
123 123
     }
@@ -137,18 +137,18 @@  discard block
 block discarded – undo
137 137
 
138 138
         self::existRole(self::$model);
139 139
 
140
-		foreach ( self::$validators[self::$model]->getRules($request['ROLE'])  as $field => $r) {
140
+		foreach (self::$validators[self::$model]->getRules($request['ROLE'])  as $field => $r) {
141 141
             $r = self::replaceRegex($r);
142 142
             $response .= ("{$field}:".json_encode(array_reverse($r))).',';
143 143
         }
144 144
 
145
-        return '{'.substr($response,0,-1).'}';
145
+        return '{'.substr($response, 0, -1).'}';
146 146
     }
147 147
     
148 148
     private static function replaceRegex(array $rules): array
149 149
     {
150
-        if(array_key_exists('regex',$rules)){ 
151
-            $rules['regex'] = substr($rules['regex'],1,-2);
150
+        if (array_key_exists('regex', $rules)) { 
151
+            $rules['regex'] = substr($rules['regex'], 1, -2);
152 152
         }
153 153
         return $rules;
154 154
     }
Please login to merge, or discard this patch.
src/ExtraCheck.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 
13 13
     protected static function checkRequireds(): void
14 14
     {
15
-        if(count(self::$required) > 0){
15
+        if (count(self::$required)>0) {
16 16
             self::$errors[] = [
17
-                'As seguintes informações não poderam ser validadas: '.implode(', ',array_keys(self::$required)).'.'
17
+                'As seguintes informações não poderam ser validadas: '.implode(', ', array_keys(self::$required)).'.'
18 18
             ];
19 19
         }
20 20
     }
@@ -22,22 +22,22 @@  discard block
 block discarded – undo
22 22
     public static function validateDate($date, $format = 'Y-m-d H:i:s')
23 23
     {
24 24
         $d = \DateTime::createFromFormat($format, $date);
25
-        return $d && $d->format($format) == $date;
25
+        return $d && $d->format($format)==$date;
26 26
     }
27 27
 
28 28
     protected static function checkRequired(string $param): bool
29 29
     {
30
-        return (array_key_exists('required',self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]) && self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]['required']);
30
+        return (array_key_exists('required', self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]) && self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]['required']);
31 31
     }
32 32
 
33 33
     protected static function toNext(string $param, $value): bool
34 34
     {
35
-        return (self::checkRequired($param) || strlen($value > 0));
35
+        return (self::checkRequired($param) || strlen($value>0));
36 36
     }
37 37
 
38 38
     protected static function testArray(string $param, $value): ?array
39 39
     {
40
-        if(!is_array(json_decode($value))){
40
+        if (!is_array(json_decode($value))) {
41 41
             self::$errors[] = [
42 42
                 $param => 'Era esperado uma informação em formato array para está informação.'
43 43
             ];
Please login to merge, or discard this patch.
src/Rules.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@
 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
             self::$errors[] = "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/MiddlewareTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 block discarded – undo
6 6
 use Psr\Http\Server\RequestHandlerInterface;
7 7
 use Psr\Http\Message\ResponseInterface;
8 8
 
9
-trait MiddlewareTrait{
9
+trait MiddlewareTrait {
10 10
 
11 11
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
12 12
     {
13
-        if(!self::execute($_REQUEST)){
14
-            throw new \Exception(implode(', ',self::getErrors()));
13
+        if (!self::execute($_REQUEST)) {
14
+            throw new \Exception(implode(', ', self::getErrors()));
15 15
         }
16 16
 
17 17
         return $handler->handle($request);
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 static function checkMinlength(string $param, $value): void
10 10
     {
11
-        if(self::toNext($param,$value)){    
11
+        if (self::toNext($param, $value)) {    
12 12
             
13 13
             $realval = (is_array(self::$data[$param])) ? self::$data[$param] : [self::$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::$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::$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 static function checkRegex(string $param, $value): void
32 32
     {
33
-        if(self::toNext($param,$value)){
33
+        if (self::toNext($param, $value)) {
34 34
 
35 35
             $realval = (is_array(self::$data[$param])) ? self::$data[$param] : [self::$data[$param]];
36 36
 
37
-            foreach($realval as $val){
37
+            foreach ($realval as $val) {
38 38
 
39
-                if(!preg_match(self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]['regex'], $val)){
39
+                if (!preg_match(self::$validators[self::$model]->getRules(self::$data['ROLE'])[$param]['regex'], $val)) {
40 40
                     self::$errors[] = [
41 41
                         $param => 'inválido(a).'
42 42
                     ];
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 
49 49
     protected static function checkMincount(string $param, $value): void
50 50
     {
51
-        if(self::toNext($param,$value)){
51
+        if (self::toNext($param, $value)) {
52 52
             $array = self::testArray($param, self::$data[$param]);
53
-            if(count($array) < $value){
53
+            if (count($array)<$value) {
54 54
                 self::$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 static function checkMaxcount(string $param, $value): void
62 62
     {
63
-        if(self::toNext($param,$value)){
63
+        if (self::toNext($param, $value)) {
64 64
             $array = self::testArray($param, self::$data[$param]);
65
-            if(count($array) > $value){
65
+            if (count($array)>$value) {
66 66
                 self::$errors[] = [
67 67
                     $param => 'ultrapassou o esperado.'
68 68
                 ];
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 
73 73
     protected static function checkEquals(string $param, $value): void
74 74
     {
75
-        if(self::toNext($param,$value)){
75
+        if (self::toNext($param, $value)) {
76 76
 
77
-            if(!array_key_exists($param,json_decode(self::$data['data'],true))){
77
+            if (!array_key_exists($param, json_decode(self::$data['data'], true))) {
78 78
                 self::$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::$data[$param] != json_decode(self::$data['data'],true)[$value]){
83
+            if (self::$data[$param]!=json_decode(self::$data['data'], true)[$value]) {
84 84
                 self::$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 static function checkMaxlength(string $param, $value)
93 93
     {
94
-        if(self::toNext($param,$value)){
94
+        if (self::toNext($param, $value)) {
95 95
 
96 96
             $realval = (is_array(self::$data[$param])) ? self::$data[$param] : [self::$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::$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 static function checkType(string $param, $value)
111 111
     {
112
-        if(self::toNext($param,$value)){
112
+        if (self::toNext($param, $value)) {
113 113
 
114 114
             switch ($value) {
115 115
                 case 'date':
116
-                    if(!self::validateDate(self::$data[$param] , 'd/m/Y')){
116
+                    if (!self::validateDate(self::$data[$param], 'd/m/Y')) {
117 117
                         self::$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 static function checkFilter(string $param, $value)
127 127
     {
128
-        if(self::toNext($param,$value)){
128
+        if (self::toNext($param, $value)) {
129 129
 
130
-            if(!filter_var(self::$data[$param], $value)){
130
+            if (!filter_var(self::$data[$param], $value)) {
131 131
                 self::$errors[] = [
132 132
                     $param => 'não passou pela filtragem de dados.'
133 133
                 ];
Please login to merge, or discard this patch.
examples/MiddlewareUseExample.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
 use HnrAzevedo\Router\Router;
15 15
 use Psr\Http\Server\MiddlewareInterface;
16 16
 
17
-try{
17
+try {
18 18
     $serverRequest = (new Factory())->createServerRequest($_SERVER['REQUEST_METHOD'], new Uri($_SERVER['REQUEST_URI']));
19 19
 
20
-    class App implements MiddlewareInterface{
20
+    class App implements MiddlewareInterface {
21 21
         public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
22 22
         {
23
-            if(empty($request->getAttribute('route')))
23
+            if (empty($request->getAttribute('route')))
24 24
             {
25 25
                 throw new Exception('Page not found', 404);
26 26
             }
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         }
32 32
     }
33 33
 
34
-    define('GLOBAL_MIDDLEWARES',[
34
+    define('GLOBAL_MIDDLEWARES', [
35 35
         Router::class,
36 36
         App::class
37 37
     ]);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
     function runMiddlewares($serverRequest)
69 69
     {
70
-        nextExample(new class implements RequestHandlerInterface{
70
+        nextExample(new class implements RequestHandlerInterface {
71 71
             public function handle(ServerRequestInterface $request): ResponseInterface
72 72
             {
73 73
                 return (new Factory())->createResponse(200);
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
     runMiddlewares($serverRequest);
79 79
 
80
-}catch(Exception $er){
80
+}catch (Exception $er) {
81 81
 
82 82
     die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}.");
83 83
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 
78 78
     runMiddlewares($serverRequest);
79 79
 
80
-}catch(Exception $er){
80
+} catch(Exception $er){
81 81
 
82 82
     die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}.");
83 83
 
Please login to merge, or discard this patch.
examples/DefaultUseExample.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,23 +10,23 @@  discard block
 block discarded – undo
10 10
     'password' => 123456,
11 11
     'password2' => 123456,
12 12
     'phones' => [
13
-        '949164770','949164771','949164772'
13
+        '949164770', '949164771', '949164772'
14 14
     ],
15 15
     'birth' => '28/09/1996',
16 16
     'PROVIDER' => 'user',
17 17
     'ROLE' => 'login'
18 18
 ];
19 19
 
20
-try{
20
+try {
21 21
 
22 22
     /* Checks whether the passed data is valid for the selected function */
23 23
     $valid = Validator::namespace('Example\\Rules')->execute($data);
24 24
     
25
-    if(!$valid){
25
+    if (!$valid) {
26 26
         $errors = [];
27
-        foreach(Validator::getErrors() as $err => $message){
27
+        foreach (Validator::getErrors() as $err => $message) {
28 28
             $errors[] = [
29
-                'input' => array_keys($message)[0],                 // Return name input error
29
+                'input' => array_keys($message)[0], // Return name input error
30 30
                 'message' => $message[array_keys($message)[0]]      // Return message error
31 31
             ];
32 32
         }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     var_dump($json);
39 39
 
40
-}catch(Exception $er){
40
+}catch (Exception $er) {
41 41
 
42 42
     die("Code Error: {$er->getCode()}<br> Line: {$er->getLine()}<br> File: {$er->getFile()}<br> Message: {$er->getMessage()}");
43 43
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 
38 38
     var_dump($json);
39 39
 
40
-}catch(Exception $er){
40
+} catch(Exception $er){
41 41
 
42 42
     die("Code Error: {$er->getCode()}<br> Line: {$er->getLine()}<br> File: {$er->getFile()}<br> Message: {$er->getMessage()}");
43 43
 
Please login to merge, or discard this patch.