@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | self::$errors[] = $er->getMessage(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return self::checkErrors(); |
|
| 84 | + return self::checkErrors(); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | public static function checkErrors(): bool |
@@ -93,21 +93,21 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) { |
| 95 | 95 | |
| 96 | - foreach (self::$data as $keyy => $valuee) { |
|
| 96 | + foreach (self::$data as $keyy => $valuee) { |
|
| 97 | 97 | |
| 98 | - self::checkExpected($keyy); |
|
| 98 | + self::checkExpected($keyy); |
|
| 99 | 99 | |
| 100 | - if($keyy===$key){ |
|
| 100 | + if($keyy===$key){ |
|
| 101 | 101 | |
| 102 | 102 | unset(self::$required[$key]); |
| 103 | 103 | |
| 104 | - foreach ($value as $subkey => $subvalue) { |
|
| 104 | + foreach ($value as $subkey => $subvalue) { |
|
| 105 | 105 | $function = "check".ucfirst($subkey); |
| 106 | 106 | self::testMethod($function); |
| 107 | 107 | self::$function($keyy,$subvalue); |
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | self::existRole(self::$model); |
| 147 | 147 | |
| 148 | - foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
| 148 | + foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
| 149 | 149 | $r = self::replaceRegex($r); |
| 150 | 150 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 151 | 151 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 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 |
||
| 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,21 +42,21 @@ discard block |
||
| 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 | } |
| 56 | 56 | |
| 57 | 57 | public static function execute(array $data): bool |
| 58 | 58 | { |
| 59 | - try{ |
|
| 59 | + try { |
|
| 60 | 60 | self::getInstance()->checkDatas($data); |
| 61 | 61 | |
| 62 | 62 | self::$data = $data; |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | self::existRole(self::$model); |
| 69 | 69 | |
| 70 | - foreach ( (self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) { |
|
| 71 | - if(@$value['required'] === true){ |
|
| 70 | + foreach ((self::$validators[self::$model]->getRules($data['ROLE'])) as $key => $value) { |
|
| 71 | + if (@$value['required']===true) { |
|
| 72 | 72 | self::$required[$key] = $value; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | self::validate(); |
| 79 | 79 | self::checkRequireds(); |
| 80 | - }catch(\Exception $er){ |
|
| 80 | + }catch (\Exception $er) { |
|
| 81 | 81 | self::$errors[] = $er->getMessage(); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,25 +86,25 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public static function checkErrors(): bool |
| 88 | 88 | { |
| 89 | - return (count(self::$errors) === 0); |
|
| 89 | + return (count(self::$errors)===0); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public static function validate(): void |
| 93 | 93 | { |
| 94 | - foreach ( (self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) { |
|
| 94 | + foreach ((self::$validators[self::$model]->getRules(self::$data['ROLE'])) as $key => $value) { |
|
| 95 | 95 | |
| 96 | 96 | foreach (self::$data as $keyy => $valuee) { |
| 97 | 97 | |
| 98 | 98 | self::checkExpected($keyy); |
| 99 | 99 | |
| 100 | - if($keyy===$key){ |
|
| 100 | + if ($keyy===$key) { |
|
| 101 | 101 | |
| 102 | 102 | unset(self::$required[$key]); |
| 103 | 103 | |
| 104 | 104 | foreach ($value as $subkey => $subvalue) { |
| 105 | 105 | $function = "check".ucfirst($subkey); |
| 106 | 106 | self::testMethod($function); |
| 107 | - self::$function($keyy,$subvalue); |
|
| 107 | + self::$function($keyy, $subvalue); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | private static function checkExpected(string $keyy): void |
| 115 | 115 | { |
| 116 | - if(!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE'])) ) && !in_array($keyy,self::getInstance()->defaultData)){ |
|
| 116 | + if (!array_key_exists($keyy, (self::$validators[self::$model]->getRules(self::$data['ROLE']))) && !in_array($keyy, self::getInstance()->defaultData)) { |
|
| 117 | 117 | throw new \RuntimeException("O campo '{$keyy}' não é esperado para está operação"); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public static function testMethod($method) |
| 127 | 127 | { |
| 128 | - if(!method_exists(static::class, $method)){ |
|
| 128 | + if (!method_exists(static::class, $method)) { |
|
| 129 | 129 | throw new \RuntimeException("{$method} não é uma validação válida"); |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -145,18 +145,18 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | self::existRole(self::$model); |
| 147 | 147 | |
| 148 | - foreach ( self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
| 148 | + foreach (self::$validators[self::$model]->getRules($request['ROLE']) as $field => $r) { |
|
| 149 | 149 | $r = self::replaceRegex($r); |
| 150 | 150 | $response .= ("{$field}:".json_encode(array_reverse($r))).','; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - return '{'.substr($response,0,-1).'}'; |
|
| 153 | + return '{'.substr($response, 0, -1).'}'; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | private static function replaceRegex(array $rules): array |
| 157 | 157 | { |
| 158 | - if(array_key_exists('regex',$rules)){ |
|
| 159 | - $rules['regex'] = substr($rules['regex'],1,-2); |
|
| 158 | + if (array_key_exists('regex', $rules)) { |
|
| 159 | + $rules['regex'] = substr($rules['regex'], 1, -2); |
|
| 160 | 160 | } |
| 161 | 161 | return $rules; |
| 162 | 162 | } |