@@ -51,20 +51,20 @@ |
||
| 51 | 51 | public function url(string $url, ?array $schemas = null, ?string $defaultSchema = null): bool |
| 52 | 52 | { |
| 53 | 53 | //Add default schema if not presented |
| 54 | - if (!empty($defaultSchema) && !$this->hasSchema($url)) { |
|
| 54 | + if (!empty($defaultSchema) && !$this->hasSchema($url)){ |
|
| 55 | 55 | $defaultSchema = $this->trimSchema($defaultSchema); |
| 56 | - if (!empty($defaultSchema)) { |
|
| 56 | + if (!empty($defaultSchema)){ |
|
| 57 | 57 | $url = "$defaultSchema://{$this->trimURL($url)}"; |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if (empty($schemas)) { |
|
| 61 | + if (empty($schemas)){ |
|
| 62 | 62 | return (bool)filter_var($url, FILTER_VALIDATE_URL); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - foreach ($schemas as $schema) { |
|
| 65 | + foreach ($schemas as $schema){ |
|
| 66 | 66 | $schema = $this->trimSchema($schema); |
| 67 | - if (empty($schema) || !$this->containsSchema($url, $schema)) { |
|
| 67 | + if (empty($schema) || !$this->containsSchema($url, $schema)){ |
|
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -51,20 +51,25 @@ |
||
| 51 | 51 | public function url(string $url, ?array $schemas = null, ?string $defaultSchema = null): bool |
| 52 | 52 | { |
| 53 | 53 | //Add default schema if not presented |
| 54 | - if (!empty($defaultSchema) && !$this->hasSchema($url)) { |
|
| 54 | + if (!empty($defaultSchema) && !$this->hasSchema($url)) |
|
| 55 | + { |
|
| 55 | 56 | $defaultSchema = $this->trimSchema($defaultSchema); |
| 56 | - if (!empty($defaultSchema)) { |
|
| 57 | + if (!empty($defaultSchema)) |
|
| 58 | + { |
|
| 57 | 59 | $url = "$defaultSchema://{$this->trimURL($url)}"; |
| 58 | 60 | } |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | - if (empty($schemas)) { |
|
| 63 | + if (empty($schemas)) |
|
| 64 | + { |
|
| 62 | 65 | return (bool)filter_var($url, FILTER_VALIDATE_URL); |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | - foreach ($schemas as $schema) { |
|
| 68 | + foreach ($schemas as $schema) |
|
| 69 | + { |
|
| 66 | 70 | $schema = $this->trimSchema($schema); |
| 67 | - if (empty($schema) || !$this->containsSchema($url, $schema)) { |
|
| 71 | + if (empty($schema) || !$this->containsSchema($url, $schema)) |
|
| 72 | + { |
|
| 68 | 73 | continue; |
| 69 | 74 | } |
| 70 | 75 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function cardNumber($value): bool |
| 38 | 38 | { |
| 39 | - if (!is_string($value) || strlen($value) < 12) { |
|
| 39 | + if (!is_string($value) || strlen($value) < 12){ |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ($value !== preg_replace('/\D+/', '', $value)) { |
|
| 43 | + if ($value !== preg_replace('/\D+/', '', $value)){ |
|
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $odd = strlen($value) % 2; |
| 49 | 49 | |
| 50 | 50 | $length = strlen($value); |
| 51 | - for ($i = 0; $i < $length; ++$i) { |
|
| 51 | + for ($i = 0; $i < $length; ++$i){ |
|
| 52 | 52 | $result += $odd |
| 53 | 53 | ? $value[$i] |
| 54 | 54 | : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function match($value, string $field, bool $strict = false): bool |
| 72 | 72 | { |
| 73 | - if ($strict) { |
|
| 73 | + if ($strict){ |
|
| 74 | 74 | return $value === $this->getValidator()->getValue($field, null); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -36,11 +36,13 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function cardNumber($value): bool |
| 38 | 38 | { |
| 39 | - if (!is_string($value) || strlen($value) < 12) { |
|
| 39 | + if (!is_string($value) || strlen($value) < 12) |
|
| 40 | + { |
|
| 40 | 41 | return false; |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | - if ($value !== preg_replace('/\D+/', '', $value)) { |
|
| 44 | + if ($value !== preg_replace('/\D+/', '', $value)) |
|
| 45 | + { |
|
| 44 | 46 | return false; |
| 45 | 47 | } |
| 46 | 48 | |
@@ -48,7 +50,8 @@ discard block |
||
| 48 | 50 | $odd = strlen($value) % 2; |
| 49 | 51 | |
| 50 | 52 | $length = strlen($value); |
| 51 | - for ($i = 0; $i < $length; ++$i) { |
|
| 53 | + for ($i = 0; $i < $length; ++$i) |
|
| 54 | + { |
|
| 52 | 55 | $result += $odd |
| 53 | 56 | ? $value[$i] |
| 54 | 57 | : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2); |
@@ -70,7 +73,8 @@ discard block |
||
| 70 | 73 | */ |
| 71 | 74 | public function match($value, string $field, bool $strict = false): bool |
| 72 | 75 | { |
| 73 | - if ($strict) { |
|
| 76 | + if ($strict) |
|
| 77 | + { |
|
| 74 | 78 | return $value === $this->getValidator()->getValue($field, null); |
| 75 | 79 | } |
| 76 | 80 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | public function future($value, bool $orNow = false, bool $useMicroSeconds = false): bool |
| 49 | 49 | { |
| 50 | 50 | $compare = $this->compare($this->date($value), $this->now(), $useMicroSeconds); |
| 51 | - if (is_bool($compare)) { |
|
| 51 | + if (is_bool($compare)){ |
|
| 52 | 52 | return $compare; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function past($value, bool $orNow = false, bool $useMicroSeconds = false): bool |
| 67 | 67 | { |
| 68 | 68 | $compare = $this->compare($this->date($value), $this->now(), $useMicroSeconds); |
| 69 | - if (is_bool($compare)) { |
|
| 69 | + if (is_bool($compare)){ |
|
| 70 | 70 | return $compare; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function format($value, string $format): bool |
| 84 | 84 | { |
| 85 | - if (!$this->isApplicableValue($value)) { |
|
| 85 | + if (!$this->isApplicableValue($value)){ |
|
| 86 | 86 | return false; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | public function timezone($value): bool |
| 112 | 112 | { |
| 113 | - if (!is_scalar($value)) { |
|
| 113 | + if (!is_scalar($value)){ |
|
| 114 | 114 | return false; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | public function before($value, string $field, bool $orEquals = false, bool $useMicroSeconds = false): bool |
| 130 | 130 | { |
| 131 | 131 | $compare = $this->compare($this->date($value), $this->thresholdFromField($field), $useMicroSeconds); |
| 132 | - if (is_bool($compare)) { |
|
| 132 | + if (is_bool($compare)){ |
|
| 133 | 133 | return $compare; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | public function after($value, string $field, bool $orEquals = false, bool $useMicroSeconds = false): bool |
| 149 | 149 | { |
| 150 | 150 | $compare = $this->compare($this->date($value), $this->thresholdFromField($field), $useMicroSeconds); |
| 151 | - if (is_bool($compare)) { |
|
| 151 | + if (is_bool($compare)){ |
|
| 152 | 152 | return $compare; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -161,17 +161,17 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function date($value): ?\DateTimeImmutable |
| 163 | 163 | { |
| 164 | - if (!$this->isApplicableValue($value)) { |
|
| 164 | + if (!$this->isApplicableValue($value)){ |
|
| 165 | 165 | return null; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - try { |
|
| 169 | - if (empty($value)) { |
|
| 168 | + try{ |
|
| 169 | + if (empty($value)){ |
|
| 170 | 170 | $value = '0'; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - return new \DateTimeImmutable(is_numeric($value) ? ('@' . (int)$value) : (string)$value); |
|
| 174 | - } catch (\Throwable $e) { |
|
| 173 | + return new \DateTimeImmutable(is_numeric($value) ? ('@'.(int)$value) : (string)$value); |
|
| 174 | + }catch (\Throwable $e){ |
|
| 175 | 175 | //here's the fail; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | private function now(): ?\DateTimeImmutable |
| 194 | 194 | { |
| 195 | - try { |
|
| 195 | + try{ |
|
| 196 | 196 | return new \DateTimeImmutable('now'); |
| 197 | - } catch (\Throwable $e) { |
|
| 197 | + }catch (\Throwable $e){ |
|
| 198 | 198 | //here's the fail; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | private function thresholdFromField(string $field): ?\DateTimeImmutable |
| 209 | 209 | { |
| 210 | 210 | $before = $this->getValidator()->getValue($field); |
| 211 | - if ($before !== null) { |
|
| 211 | + if ($before !== null){ |
|
| 212 | 212 | return $this->date($before); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -223,15 +223,15 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | private function compare(?\DateTimeImmutable $date, ?\DateTimeImmutable $threshold, bool $useMicroseconds) |
| 225 | 225 | { |
| 226 | - if ($date === null) { |
|
| 226 | + if ($date === null){ |
|
| 227 | 227 | return false; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ($threshold === null) { |
|
| 230 | + if ($threshold === null){ |
|
| 231 | 231 | return true; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if (!$useMicroseconds) { |
|
| 234 | + if (!$useMicroseconds){ |
|
| 235 | 235 | $date = $this->dropMicroSeconds($date); |
| 236 | 236 | $threshold = $this->dropMicroSeconds($threshold); |
| 237 | 237 | } |
@@ -48,7 +48,8 @@ discard block |
||
| 48 | 48 | public function future($value, bool $orNow = false, bool $useMicroSeconds = false): bool |
| 49 | 49 | { |
| 50 | 50 | $compare = $this->compare($this->date($value), $this->now(), $useMicroSeconds); |
| 51 | - if (is_bool($compare)) { |
|
| 51 | + if (is_bool($compare)) |
|
| 52 | + { |
|
| 52 | 53 | return $compare; |
| 53 | 54 | } |
| 54 | 55 | |
@@ -66,7 +67,8 @@ discard block |
||
| 66 | 67 | public function past($value, bool $orNow = false, bool $useMicroSeconds = false): bool |
| 67 | 68 | { |
| 68 | 69 | $compare = $this->compare($this->date($value), $this->now(), $useMicroSeconds); |
| 69 | - if (is_bool($compare)) { |
|
| 70 | + if (is_bool($compare)) |
|
| 71 | + { |
|
| 70 | 72 | return $compare; |
| 71 | 73 | } |
| 72 | 74 | |
@@ -82,7 +84,8 @@ discard block |
||
| 82 | 84 | */ |
| 83 | 85 | public function format($value, string $format): bool |
| 84 | 86 | { |
| 85 | - if (!$this->isApplicableValue($value)) { |
|
| 87 | + if (!$this->isApplicableValue($value)) |
|
| 88 | + { |
|
| 86 | 89 | return false; |
| 87 | 90 | } |
| 88 | 91 | |
@@ -110,7 +113,8 @@ discard block |
||
| 110 | 113 | */ |
| 111 | 114 | public function timezone($value): bool |
| 112 | 115 | { |
| 113 | - if (!is_scalar($value)) { |
|
| 116 | + if (!is_scalar($value)) |
|
| 117 | + { |
|
| 114 | 118 | return false; |
| 115 | 119 | } |
| 116 | 120 | |
@@ -129,7 +133,8 @@ discard block |
||
| 129 | 133 | public function before($value, string $field, bool $orEquals = false, bool $useMicroSeconds = false): bool |
| 130 | 134 | { |
| 131 | 135 | $compare = $this->compare($this->date($value), $this->thresholdFromField($field), $useMicroSeconds); |
| 132 | - if (is_bool($compare)) { |
|
| 136 | + if (is_bool($compare)) |
|
| 137 | + { |
|
| 133 | 138 | return $compare; |
| 134 | 139 | } |
| 135 | 140 | |
@@ -148,7 +153,8 @@ discard block |
||
| 148 | 153 | public function after($value, string $field, bool $orEquals = false, bool $useMicroSeconds = false): bool |
| 149 | 154 | { |
| 150 | 155 | $compare = $this->compare($this->date($value), $this->thresholdFromField($field), $useMicroSeconds); |
| 151 | - if (is_bool($compare)) { |
|
| 156 | + if (is_bool($compare)) |
|
| 157 | + { |
|
| 152 | 158 | return $compare; |
| 153 | 159 | } |
| 154 | 160 | |
@@ -161,17 +167,22 @@ discard block |
||
| 161 | 167 | */ |
| 162 | 168 | private function date($value): ?\DateTimeImmutable |
| 163 | 169 | { |
| 164 | - if (!$this->isApplicableValue($value)) { |
|
| 170 | + if (!$this->isApplicableValue($value)) |
|
| 171 | + { |
|
| 165 | 172 | return null; |
| 166 | 173 | } |
| 167 | 174 | |
| 168 | - try { |
|
| 169 | - if (empty($value)) { |
|
| 175 | + try |
|
| 176 | + { |
|
| 177 | + if (empty($value)) |
|
| 178 | + { |
|
| 170 | 179 | $value = '0'; |
| 171 | 180 | } |
| 172 | 181 | |
| 173 | 182 | return new \DateTimeImmutable(is_numeric($value) ? ('@' . (int)$value) : (string)$value); |
| 174 | - } catch (\Throwable $e) { |
|
| 183 | + } |
|
| 184 | + catch (\Throwable $e) |
|
| 185 | + { |
|
| 175 | 186 | //here's the fail; |
| 176 | 187 | } |
| 177 | 188 | |
@@ -192,9 +203,12 @@ discard block |
||
| 192 | 203 | */ |
| 193 | 204 | private function now(): ?\DateTimeImmutable |
| 194 | 205 | { |
| 195 | - try { |
|
| 206 | + try |
|
| 207 | + { |
|
| 196 | 208 | return new \DateTimeImmutable('now'); |
| 197 | - } catch (\Throwable $e) { |
|
| 209 | + } |
|
| 210 | + catch (\Throwable $e) |
|
| 211 | + { |
|
| 198 | 212 | //here's the fail; |
| 199 | 213 | } |
| 200 | 214 | |
@@ -208,7 +222,8 @@ discard block |
||
| 208 | 222 | private function thresholdFromField(string $field): ?\DateTimeImmutable |
| 209 | 223 | { |
| 210 | 224 | $before = $this->getValidator()->getValue($field); |
| 211 | - if ($before !== null) { |
|
| 225 | + if ($before !== null) |
|
| 226 | + { |
|
| 212 | 227 | return $this->date($before); |
| 213 | 228 | } |
| 214 | 229 | |
@@ -223,15 +238,18 @@ discard block |
||
| 223 | 238 | */ |
| 224 | 239 | private function compare(?\DateTimeImmutable $date, ?\DateTimeImmutable $threshold, bool $useMicroseconds) |
| 225 | 240 | { |
| 226 | - if ($date === null) { |
|
| 241 | + if ($date === null) |
|
| 242 | + { |
|
| 227 | 243 | return false; |
| 228 | 244 | } |
| 229 | 245 | |
| 230 | - if ($threshold === null) { |
|
| 246 | + if ($threshold === null) |
|
| 247 | + { |
|
| 231 | 248 | return true; |
| 232 | 249 | } |
| 233 | 250 | |
| 234 | - if (!$useMicroseconds) { |
|
| 251 | + if (!$useMicroseconds) |
|
| 252 | + { |
|
| 235 | 253 | $date = $this->dropMicroSeconds($date); |
| 236 | 254 | $threshold = $this->dropMicroSeconds($threshold); |
| 237 | 255 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | public function __construct(array $config = []) |
| 38 | 38 | { |
| 39 | 39 | parent::__construct($config); |
| 40 | - if (!empty($this->config['aliases'])) { |
|
| 40 | + if (!empty($this->config['aliases'])){ |
|
| 41 | 41 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function getChecker(string $name): Autowire |
| 61 | 61 | { |
| 62 | - if (!$this->hasChecker($name)) { |
|
| 62 | + if (!$this->hasChecker($name)){ |
|
| 63 | 63 | throw new ValidationException("Undefined checker `{$name}``."); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $instance = $this->wire('checkers', $name); |
| 67 | - if ($instance !== null) { |
|
| 67 | + if ($instance !== null){ |
|
| 68 | 68 | return $instance; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function getCondition(string $name): Autowire |
| 88 | 88 | { |
| 89 | - if (!$this->hasCondition($name)) { |
|
| 89 | + if (!$this->hasCondition($name)){ |
|
| 90 | 90 | throw new ValidationException("Undefined condition `{$name}`."); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $instance = $this->wire('conditions', $name); |
| 94 | - if ($instance !== null) { |
|
| 94 | + if ($instance !== null){ |
|
| 95 | 95 | return $instance; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function mapFunction($function) |
| 109 | 109 | { |
| 110 | - if (is_string($function)) { |
|
| 110 | + if (is_string($function)){ |
|
| 111 | 111 | $function = $this->resolveAlias($function); |
| 112 | - if (strpos($function, ':') !== false) { |
|
| 112 | + if (strpos($function, ':') !== false){ |
|
| 113 | 113 | $function = explode(':', $function); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | private function wire(string $section, string $name): ?Autowire |
| 126 | 126 | { |
| 127 | - if (is_string($this->config[$section][$name])) { |
|
| 127 | + if (is_string($this->config[$section][$name])){ |
|
| 128 | 128 | return new Autowire($this->config[$section][$name]); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if (isset($this->config[$section][$name]['class'])) { |
|
| 131 | + if (isset($this->config[$section][$name]['class'])){ |
|
| 132 | 132 | return new Autowire( |
| 133 | 133 | $this->config[$section][$name]['class'], |
| 134 | 134 | $this->config[$section][$name]['options'] ?? [] |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | private function normalizeAliases(array $aliases): array |
| 148 | 148 | { |
| 149 | - return array_map(static function ($value) { |
|
| 149 | + return array_map(static function ($value){ |
|
| 150 | 150 | return str_replace('::', ':', $value); |
| 151 | 151 | }, $aliases); |
| 152 | 152 | } |
@@ -37,7 +37,8 @@ discard block |
||
| 37 | 37 | public function __construct(array $config = []) |
| 38 | 38 | { |
| 39 | 39 | parent::__construct($config); |
| 40 | - if (!empty($this->config['aliases'])) { |
|
| 40 | + if (!empty($this->config['aliases'])) |
|
| 41 | + { |
|
| 41 | 42 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
| 42 | 43 | } |
| 43 | 44 | } |
@@ -59,12 +60,14 @@ discard block |
||
| 59 | 60 | */ |
| 60 | 61 | public function getChecker(string $name): Autowire |
| 61 | 62 | { |
| 62 | - if (!$this->hasChecker($name)) { |
|
| 63 | + if (!$this->hasChecker($name)) |
|
| 64 | + { |
|
| 63 | 65 | throw new ValidationException("Undefined checker `{$name}``."); |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | $instance = $this->wire('checkers', $name); |
| 67 | - if ($instance !== null) { |
|
| 69 | + if ($instance !== null) |
|
| 70 | + { |
|
| 68 | 71 | return $instance; |
| 69 | 72 | } |
| 70 | 73 | |
@@ -86,12 +89,14 @@ discard block |
||
| 86 | 89 | */ |
| 87 | 90 | public function getCondition(string $name): Autowire |
| 88 | 91 | { |
| 89 | - if (!$this->hasCondition($name)) { |
|
| 92 | + if (!$this->hasCondition($name)) |
|
| 93 | + { |
|
| 90 | 94 | throw new ValidationException("Undefined condition `{$name}`."); |
| 91 | 95 | } |
| 92 | 96 | |
| 93 | 97 | $instance = $this->wire('conditions', $name); |
| 94 | - if ($instance !== null) { |
|
| 98 | + if ($instance !== null) |
|
| 99 | + { |
|
| 95 | 100 | return $instance; |
| 96 | 101 | } |
| 97 | 102 | |
@@ -107,9 +112,11 @@ discard block |
||
| 107 | 112 | */ |
| 108 | 113 | public function mapFunction($function) |
| 109 | 114 | { |
| 110 | - if (is_string($function)) { |
|
| 115 | + if (is_string($function)) |
|
| 116 | + { |
|
| 111 | 117 | $function = $this->resolveAlias($function); |
| 112 | - if (strpos($function, ':') !== false) { |
|
| 118 | + if (strpos($function, ':') !== false) |
|
| 119 | + { |
|
| 113 | 120 | $function = explode(':', $function); |
| 114 | 121 | } |
| 115 | 122 | } |
@@ -124,11 +131,13 @@ discard block |
||
| 124 | 131 | */ |
| 125 | 132 | private function wire(string $section, string $name): ?Autowire |
| 126 | 133 | { |
| 127 | - if (is_string($this->config[$section][$name])) { |
|
| 134 | + if (is_string($this->config[$section][$name])) |
|
| 135 | + { |
|
| 128 | 136 | return new Autowire($this->config[$section][$name]); |
| 129 | 137 | } |
| 130 | 138 | |
| 131 | - if (isset($this->config[$section][$name]['class'])) { |
|
| 139 | + if (isset($this->config[$section][$name]['class'])) |
|
| 140 | + { |
|
| 132 | 141 | return new Autowire( |
| 133 | 142 | $this->config[$section][$name]['class'], |
| 134 | 143 | $this->config[$section][$name]['options'] ?? [] |
@@ -146,7 +155,8 @@ discard block |
||
| 146 | 155 | */ |
| 147 | 156 | private function normalizeAliases(array $aliases): array |
| 148 | 157 | { |
| 149 | - return array_map(static function ($value) { |
|
| 158 | + return array_map(static function ($value) |
|
| 159 | + { |
|
| 150 | 160 | return str_replace('::', ':', $value); |
| 151 | 161 | }, $aliases); |
| 152 | 162 | } |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $rules = is_array($rules) ? $rules : [$rules]; |
| 31 | 31 | |
| 32 | - foreach ($rules as $rule) { |
|
| 33 | - if ($rule instanceof \Closure) { |
|
| 32 | + foreach ($rules as $rule){ |
|
| 33 | + if ($rule instanceof \Closure){ |
|
| 34 | 34 | yield null => $rule; |
| 35 | 35 | continue; |
| 36 | 36 | } |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function parseCheck($chunk) |
| 46 | 46 | { |
| 47 | - if (is_string($chunk)) { |
|
| 47 | + if (is_string($chunk)){ |
|
| 48 | 48 | $function = str_replace('::', ':', $chunk); |
| 49 | - } else { |
|
| 50 | - if (!is_array($chunk) || !isset($chunk[0])) { |
|
| 49 | + }else{ |
|
| 50 | + if (!is_array($chunk) || !isset($chunk[0])){ |
|
| 51 | 51 | throw new ParserException('Validation rule does not define any check.'); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $function = $chunk[0]; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (is_string($function)) { |
|
| 57 | + if (is_string($function)){ |
|
| 58 | 58 | return str_replace('::', ':', $function); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -66,18 +66,18 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function parseArgs($chunk): array |
| 68 | 68 | { |
| 69 | - if (!is_array($chunk)) { |
|
| 69 | + if (!is_array($chunk)){ |
|
| 70 | 70 | return []; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - foreach (self::ARGUMENTS as $index) { |
|
| 74 | - if (isset($chunk[$index])) { |
|
| 73 | + foreach (self::ARGUMENTS as $index){ |
|
| 74 | + if (isset($chunk[$index])){ |
|
| 75 | 75 | return $chunk[$index]; |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | unset($chunk[0]); |
| 80 | - foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) { |
|
| 80 | + foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index){ |
|
| 81 | 81 | unset($chunk[$index]); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function parseMessage($chunk): ?string |
| 91 | 91 | { |
| 92 | - if (!is_array($chunk)) { |
|
| 92 | + if (!is_array($chunk)){ |
|
| 93 | 93 | return null; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - foreach (self::MESSAGES as $index) { |
|
| 97 | - if (isset($chunk[$index])) { |
|
| 96 | + foreach (self::MESSAGES as $index){ |
|
| 97 | + if (isset($chunk[$index])){ |
|
| 98 | 98 | return $chunk[$index]; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function parseConditions($chunk): array |
| 109 | 109 | { |
| 110 | - foreach (self::CONDITIONS as $index) { |
|
| 111 | - if (isset($chunk[$index])) { |
|
| 110 | + foreach (self::CONDITIONS as $index){ |
|
| 111 | + if (isset($chunk[$index])){ |
|
| 112 | 112 | $conditions = []; |
| 113 | - foreach ((array)$chunk[$index] as $key => $value) { |
|
| 114 | - if (is_numeric($key)) { |
|
| 113 | + foreach ((array)$chunk[$index] as $key => $value){ |
|
| 114 | + if (is_numeric($key)){ |
|
| 115 | 115 | $conditions[$value] = []; |
| 116 | - } else { |
|
| 116 | + }else{ |
|
| 117 | 117 | $conditions[$key] = (array)$value; |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -29,8 +29,10 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $rules = is_array($rules) ? $rules : [$rules]; |
| 31 | 31 | |
| 32 | - foreach ($rules as $rule) { |
|
| 33 | - if ($rule instanceof \Closure) { |
|
| 32 | + foreach ($rules as $rule) |
|
| 33 | + { |
|
| 34 | + if ($rule instanceof \Closure) |
|
| 35 | + { |
|
| 34 | 36 | yield null => $rule; |
| 35 | 37 | continue; |
| 36 | 38 | } |
@@ -44,17 +46,22 @@ discard block |
||
| 44 | 46 | */ |
| 45 | 47 | public function parseCheck($chunk) |
| 46 | 48 | { |
| 47 | - if (is_string($chunk)) { |
|
| 49 | + if (is_string($chunk)) |
|
| 50 | + { |
|
| 48 | 51 | $function = str_replace('::', ':', $chunk); |
| 49 | - } else { |
|
| 50 | - if (!is_array($chunk) || !isset($chunk[0])) { |
|
| 52 | + } |
|
| 53 | + else |
|
| 54 | + { |
|
| 55 | + if (!is_array($chunk) || !isset($chunk[0])) |
|
| 56 | + { |
|
| 51 | 57 | throw new ParserException('Validation rule does not define any check.'); |
| 52 | 58 | } |
| 53 | 59 | |
| 54 | 60 | $function = $chunk[0]; |
| 55 | 61 | } |
| 56 | 62 | |
| 57 | - if (is_string($function)) { |
|
| 63 | + if (is_string($function)) |
|
| 64 | + { |
|
| 58 | 65 | return str_replace('::', ':', $function); |
| 59 | 66 | } |
| 60 | 67 | |
@@ -66,18 +73,22 @@ discard block |
||
| 66 | 73 | */ |
| 67 | 74 | public function parseArgs($chunk): array |
| 68 | 75 | { |
| 69 | - if (!is_array($chunk)) { |
|
| 76 | + if (!is_array($chunk)) |
|
| 77 | + { |
|
| 70 | 78 | return []; |
| 71 | 79 | } |
| 72 | 80 | |
| 73 | - foreach (self::ARGUMENTS as $index) { |
|
| 74 | - if (isset($chunk[$index])) { |
|
| 81 | + foreach (self::ARGUMENTS as $index) |
|
| 82 | + { |
|
| 83 | + if (isset($chunk[$index])) |
|
| 84 | + { |
|
| 75 | 85 | return $chunk[$index]; |
| 76 | 86 | } |
| 77 | 87 | } |
| 78 | 88 | |
| 79 | 89 | unset($chunk[0]); |
| 80 | - foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) { |
|
| 90 | + foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) |
|
| 91 | + { |
|
| 81 | 92 | unset($chunk[$index]); |
| 82 | 93 | } |
| 83 | 94 | |
@@ -89,12 +100,15 @@ discard block |
||
| 89 | 100 | */ |
| 90 | 101 | public function parseMessage($chunk): ?string |
| 91 | 102 | { |
| 92 | - if (!is_array($chunk)) { |
|
| 103 | + if (!is_array($chunk)) |
|
| 104 | + { |
|
| 93 | 105 | return null; |
| 94 | 106 | } |
| 95 | 107 | |
| 96 | - foreach (self::MESSAGES as $index) { |
|
| 97 | - if (isset($chunk[$index])) { |
|
| 108 | + foreach (self::MESSAGES as $index) |
|
| 109 | + { |
|
| 110 | + if (isset($chunk[$index])) |
|
| 111 | + { |
|
| 98 | 112 | return $chunk[$index]; |
| 99 | 113 | } |
| 100 | 114 | } |
@@ -107,13 +121,19 @@ discard block |
||
| 107 | 121 | */ |
| 108 | 122 | public function parseConditions($chunk): array |
| 109 | 123 | { |
| 110 | - foreach (self::CONDITIONS as $index) { |
|
| 111 | - if (isset($chunk[$index])) { |
|
| 124 | + foreach (self::CONDITIONS as $index) |
|
| 125 | + { |
|
| 126 | + if (isset($chunk[$index])) |
|
| 127 | + { |
|
| 112 | 128 | $conditions = []; |
| 113 | - foreach ((array)$chunk[$index] as $key => $value) { |
|
| 114 | - if (is_numeric($key)) { |
|
| 129 | + foreach ((array)$chunk[$index] as $key => $value) |
|
| 130 | + { |
|
| 131 | + if (is_numeric($key)) |
|
| 132 | + { |
|
| 115 | 133 | $conditions[$value] = []; |
| 116 | - } else { |
|
| 134 | + } |
|
| 135 | + else |
|
| 136 | + { |
|
| 117 | 137 | $conditions[$key] = (array)$value; |
| 118 | 138 | } |
| 119 | 139 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | string $method, |
| 39 | 39 | array $args = [], |
| 40 | 40 | ?string $message = null |
| 41 | - ) { |
|
| 41 | + ){ |
|
| 42 | 42 | $this->checker = $checker; |
| 43 | 43 | $this->method = $method; |
| 44 | 44 | $this->args = $args; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getMessage(string $field, $value): string |
| 68 | 68 | { |
| 69 | - if (!empty($this->message)) { |
|
| 69 | + if (!empty($this->message)){ |
|
| 70 | 70 | return Translator::interpolate( |
| 71 | 71 | $this->message, |
| 72 | 72 | array_merge([$value, $field], $this->args) |
@@ -66,7 +66,8 @@ |
||
| 66 | 66 | */ |
| 67 | 67 | public function getMessage(string $field, $value): string |
| 68 | 68 | { |
| 69 | - if (!empty($this->message)) { |
|
| 69 | + if (!empty($this->message)) |
|
| 70 | + { |
|
| 70 | 71 | return Translator::interpolate( |
| 71 | 72 | $this->message, |
| 72 | 73 | array_merge([$value, $field], $this->args) |
@@ -27,8 +27,8 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 29 | 29 | { |
| 30 | - foreach ($this->options as $option) { |
|
| 31 | - if (empty($validator->getValue($option))) { |
|
| 30 | + foreach ($this->options as $option){ |
|
| 31 | + if (empty($validator->getValue($option))){ |
|
| 32 | 32 | return true; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -27,8 +27,10 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 29 | 29 | { |
| 30 | - foreach ($this->options as $option) { |
|
| 31 | - if (empty($validator->getValue($option))) { |
|
| 30 | + foreach ($this->options as $option) |
|
| 31 | + { |
|
| 32 | + if (empty($validator->getValue($option))) |
|
| 33 | + { |
|
| 32 | 34 | return true; |
| 33 | 35 | } |
| 34 | 36 | } |
@@ -32,8 +32,8 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 34 | 34 | { |
| 35 | - foreach ($this->compositor->makeConditions($field, $this->options) as $condition) { |
|
| 36 | - if ($condition->isMet($validator, $field, $value)) { |
|
| 35 | + foreach ($this->compositor->makeConditions($field, $this->options) as $condition){ |
|
| 36 | + if ($condition->isMet($validator, $field, $value)){ |
|
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -32,8 +32,10 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 34 | 34 | { |
| 35 | - foreach ($this->compositor->makeConditions($field, $this->options) as $condition) { |
|
| 36 | - if ($condition->isMet($validator, $field, $value)) { |
|
| 35 | + foreach ($this->compositor->makeConditions($field, $this->options) as $condition) |
|
| 36 | + { |
|
| 37 | + if ($condition->isMet($validator, $field, $value)) |
|
| 38 | + { |
|
| 37 | 39 | return false; |
| 38 | 40 | } |
| 39 | 41 | } |
@@ -27,8 +27,8 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 29 | 29 | { |
| 30 | - foreach ($this->options as $option) { |
|
| 31 | - if (!empty($validator->getValue($option))) { |
|
| 30 | + foreach ($this->options as $option){ |
|
| 31 | + if (!empty($validator->getValue($option))){ |
|
| 32 | 32 | return false; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -27,8 +27,10 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function isMet(ValidatorInterface $validator, string $field, $value): bool |
| 29 | 29 | { |
| 30 | - foreach ($this->options as $option) { |
|
| 31 | - if (!empty($validator->getValue($option))) { |
|
| 30 | + foreach ($this->options as $option) |
|
| 31 | + { |
|
| 32 | + if (!empty($validator->getValue($option))) |
|
| 33 | + { |
|
| 32 | 34 | return false; |
| 33 | 35 | } |
| 34 | 36 | } |