@@ -20,13 +20,13 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | /** @var array */ |
| 23 | - private $errors = []; |
|
| 23 | + private $errors = [ ]; |
|
| 24 | 24 | /** @var array */ |
| 25 | - private $namings = []; |
|
| 25 | + private $namings = [ ]; |
|
| 26 | 26 | /** @var array */ |
| 27 | - private $customErrorsWithInputName = []; |
|
| 27 | + private $customErrorsWithInputName = [ ]; |
|
| 28 | 28 | /** @var array */ |
| 29 | - private $customErrors = []; |
|
| 29 | + private $customErrors = [ ]; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Constructor is not allowed because Validoo uses its own |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | foreach ($rules as $input => $input_rules) { |
| 54 | 54 | if (is_array($input_rules)) { |
| 55 | 55 | foreach ($input_rules as $rule => $closure) { |
| 56 | - if (!isset($inputs[(string)$input])) |
|
| 56 | + if (!isset($inputs[ (string) $input ])) |
|
| 57 | 57 | $input_value = null; |
| 58 | 58 | else |
| 59 | - $input_value = $inputs[(string)$input]; |
|
| 59 | + $input_value = $inputs[ (string) $input ]; |
|
| 60 | 60 | /** |
| 61 | 61 | * if the key of the $input_rules is numeric that means |
| 62 | 62 | * it's neither an anonymous nor an user function. |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | $rule = $closure; |
| 66 | 66 | } |
| 67 | 67 | $rule_and_params = static::getParams($rule); |
| 68 | - $params = $real_params = $rule_and_params['params']; |
|
| 69 | - $rule = $rule_and_params['rule']; |
|
| 68 | + $params = $real_params = $rule_and_params[ 'params' ]; |
|
| 69 | + $rule = $rule_and_params[ 'rule' ]; |
|
| 70 | 70 | $params = static::getParamValues($params, $inputs); |
| 71 | 71 | array_unshift($params, $input_value); |
| 72 | 72 | /** |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | throw new ValidooException(ValidooException::UNKNOWN_RULE, $rule); |
| 90 | 90 | } |
| 91 | 91 | if ($validation == false) { |
| 92 | - $errors[(string)$input][(string)$rule]['result'] = false; |
|
| 93 | - $errors[(string)$input][(string)$rule]['params'] = $real_params; |
|
| 92 | + $errors[ (string) $input ][ (string) $rule ][ 'result' ] = false; |
|
| 93 | + $errors[ (string) $input ][ (string) $rule ][ 'params' ] = $real_params; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } else { |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | if (preg_match("#^([\w]+)\((.+?)\)$#", $rule, $matches)) { |
| 111 | 111 | return [ |
| 112 | - 'rule' => $matches[1], |
|
| 113 | - 'params' => explode(',', $matches[2]) |
|
| 112 | + 'rule' => $matches[ 1 ], |
|
| 113 | + 'params' => explode(',', $matches[ 2 ]) |
|
| 114 | 114 | ]; |
| 115 | 115 | } |
| 116 | 116 | return [ |
| 117 | 117 | 'rule' => $rule, |
| 118 | - 'params' => [] |
|
| 118 | + 'params' => [ ] |
|
| 119 | 119 | ]; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | foreach ($params as $key => $param) { |
| 132 | 132 | if (preg_match("#^:([\w]+)$#", $param, $param_type)) { |
| 133 | - $params[$key] = @$inputs[(string)$param_type[1]]; |
|
| 133 | + $params[ $key ] = @$inputs[ (string) $param_type[ 1 ] ]; |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | return $params; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | protected static function integer($input): bool |
| 171 | 171 | { |
| 172 | - return is_int($input) || ($input == (string)(int)$input); |
|
| 172 | + return is_int($input) || ($input == (string) (int) $input); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | protected static function float($input): bool |
| 180 | 180 | { |
| 181 | - return is_float($input) || ($input == (string)(float)$input); |
|
| 181 | + return is_float($input) || ($input == (string) (float) $input); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -292,9 +292,9 @@ discard block |
||
| 292 | 292 | // handle input.rule eg (name.required) |
| 293 | 293 | if (preg_match("#^(.+?)\.(.+?)$#", $key, $matches)) { |
| 294 | 294 | // $this->customErrorsWithInputName[name][required] = error message |
| 295 | - $this->customErrorsWithInputName[(string)$matches[1]][(string)$matches[2]] = $value; |
|
| 295 | + $this->customErrorsWithInputName[ (string) $matches[ 1 ] ][ (string) $matches[ 2 ] ] = $value; |
|
| 296 | 296 | } else { |
| 297 | - $this->customErrors[(string)$key] = $value; |
|
| 297 | + $this->customErrors[ (string) $key ] = $value; |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | if (null === $lang) |
| 310 | 310 | $lang = $this->getDefaultLang(); |
| 311 | 311 | |
| 312 | - $error_results = []; |
|
| 312 | + $error_results = [ ]; |
|
| 313 | 313 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
| 314 | 314 | $custom_error_texts = $this->getCustomErrorTexts($lang); |
| 315 | 315 | |
@@ -319,19 +319,19 @@ discard block |
||
| 319 | 319 | /** |
| 320 | 320 | * if parameters are input name they should be named as well |
| 321 | 321 | */ |
| 322 | - $result['params'] = $this->handleParameterNaming($result['params']); |
|
| 322 | + $result[ 'params' ] = $this->handleParameterNaming($result[ 'params' ]); |
|
| 323 | 323 | // if there is a custom message with input name, apply it |
| 324 | - if (isset($this->customErrorsWithInputName[(string)$input_name][(string)$rule])) { |
|
| 325 | - $error_message = $this->customErrorsWithInputName[(string)$input_name][(string)$rule]; |
|
| 324 | + if (isset($this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ])) { |
|
| 325 | + $error_message = $this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ]; |
|
| 326 | 326 | } // if there is a custom message for the rule, apply it |
| 327 | - else if (isset($this->customErrors[(string)$rule])) { |
|
| 328 | - $error_message = $this->customErrors[(string)$rule]; |
|
| 327 | + else if (isset($this->customErrors[ (string) $rule ])) { |
|
| 328 | + $error_message = $this->customErrors[ (string) $rule ]; |
|
| 329 | 329 | } // if there is a custom validator try to fetch from its error file |
| 330 | - else if (isset($custom_error_texts[(string)$rule])) { |
|
| 331 | - $error_message = $custom_error_texts[(string)$rule]; |
|
| 330 | + else if (isset($custom_error_texts[ (string) $rule ])) { |
|
| 331 | + $error_message = $custom_error_texts[ (string) $rule ]; |
|
| 332 | 332 | } // if none try to fetch from default error file |
| 333 | - else if (isset($default_error_texts[(string)$rule])) { |
|
| 334 | - $error_message = $default_error_texts[(string)$rule]; |
|
| 333 | + else if (isset($default_error_texts[ (string) $rule ])) { |
|
| 334 | + $error_message = $default_error_texts[ (string) $rule ]; |
|
| 335 | 335 | } else { |
| 336 | 336 | throw new ValidooException(ValidooException::NO_ERROR_TEXT, $rule); |
| 337 | 337 | } |
@@ -339,10 +339,10 @@ discard block |
||
| 339 | 339 | * handle :params(..) |
| 340 | 340 | */ |
| 341 | 341 | if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
| 342 | - foreach ($param_indexes[1] as $param_index) { |
|
| 343 | - $error_message = str_replace(':params(' . $param_index . ')', $result['params'][$param_index], $error_message); |
|
| 342 | + foreach ($param_indexes[ 1 ] as $param_index) { |
|
| 343 | + $error_message = str_replace(':params('.$param_index.')', $result[ 'params' ][ $param_index ], $error_message); |
|
| 344 | 344 | } |
| 345 | - $error_results[] = str_replace(':attribute', $named_input, $error_message); |
|
| 345 | + $error_results[ ] = str_replace(':attribute', $named_input, $error_message); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | return $error_results; |
@@ -370,10 +370,10 @@ discard block |
||
| 370 | 370 | protected function getDefaultErrorTexts(string $lang = null) |
| 371 | 371 | { |
| 372 | 372 | /* handle default error text file */ |
| 373 | - $default_error_texts = []; |
|
| 374 | - if (file_exists(__DIR__ . '/errors/' . $lang . '.php')) { |
|
| 373 | + $default_error_texts = [ ]; |
|
| 374 | + if (file_exists(__DIR__.'/errors/'.$lang.'.php')) { |
|
| 375 | 375 | /** @noinspection PhpIncludeInspection */ |
| 376 | - $default_error_texts = include __DIR__ . '/errors/' . $lang . '.php'; |
|
| 376 | + $default_error_texts = include __DIR__.'/errors/'.$lang.'.php'; |
|
| 377 | 377 | } |
| 378 | 378 | return $default_error_texts; |
| 379 | 379 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | protected function getCustomErrorTexts(string $lang = null) |
| 386 | 386 | { |
| 387 | 387 | /* handle error text file for custom validators */ |
| 388 | - $custom_error_texts = []; |
|
| 388 | + $custom_error_texts = [ ]; |
|
| 389 | 389 | if (file_exists($this->getErrorFilePath($lang))) { |
| 390 | 390 | /** @noinspection PhpIncludeInspection */ |
| 391 | 391 | $custom_error_texts = include $this->getErrorFilePath($lang); |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | protected function handleNaming(string $input_name) |
| 410 | 410 | { |
| 411 | - if (isset($this->namings[$input_name])) { |
|
| 412 | - $named_input = $this->namings[$input_name]; |
|
| 411 | + if (isset($this->namings[ $input_name ])) { |
|
| 412 | + $named_input = $this->namings[ $input_name ]; |
|
| 413 | 413 | } else { |
| 414 | 414 | $named_input = $input_name; |
| 415 | 415 | } |
@@ -424,10 +424,10 @@ discard block |
||
| 424 | 424 | { |
| 425 | 425 | foreach ($params as $key => $param) { |
| 426 | 426 | if (preg_match("#^:([\w]+)$#", $param, $param_type)) { |
| 427 | - if (isset($this->namings[(string)$param_type[1]])) { |
|
| 428 | - $params[$key] = $this->namings[(string)$param_type[1]]; |
|
| 427 | + if (isset($this->namings[ (string) $param_type[ 1 ] ])) { |
|
| 428 | + $params[ $key ] = $this->namings[ (string) $param_type[ 1 ] ]; |
|
| 429 | 429 | } else { |
| 430 | - $params[$key] = $param_type[1]; |
|
| 430 | + $params[ $key ] = $param_type[ 1 ]; |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | public function has(string $input_name, string $rule_name = null): bool |
| 443 | 443 | { |
| 444 | 444 | if (null !== $rule_name) |
| 445 | - return isset($this->errors[$input_name][$rule_name]); |
|
| 446 | - return isset($this->errors[$input_name]); |
|
| 445 | + return isset($this->errors[ $input_name ][ $rule_name ]); |
|
| 446 | + return isset($this->errors[ $input_name ]); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -53,10 +53,11 @@ discard block |
||
| 53 | 53 | foreach ($rules as $input => $input_rules) { |
| 54 | 54 | if (is_array($input_rules)) { |
| 55 | 55 | foreach ($input_rules as $rule => $closure) { |
| 56 | - if (!isset($inputs[(string)$input])) |
|
| 57 | - $input_value = null; |
|
| 58 | - else |
|
| 59 | - $input_value = $inputs[(string)$input]; |
|
| 56 | + if (!isset($inputs[(string)$input])) { |
|
| 57 | + $input_value = null; |
|
| 58 | + } else { |
|
| 59 | + $input_value = $inputs[(string)$input]; |
|
| 60 | + } |
|
| 60 | 61 | /** |
| 61 | 62 | * if the key of the $input_rules is numeric that means |
| 62 | 63 | * it's neither an anonymous nor an user function. |
@@ -306,8 +307,9 @@ discard block |
||
| 306 | 307 | */ |
| 307 | 308 | public function getErrors(string $lang = null): array |
| 308 | 309 | { |
| 309 | - if (null === $lang) |
|
| 310 | - $lang = $this->getDefaultLang(); |
|
| 310 | + if (null === $lang) { |
|
| 311 | + $lang = $this->getDefaultLang(); |
|
| 312 | + } |
|
| 311 | 313 | |
| 312 | 314 | $error_results = []; |
| 313 | 315 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
@@ -338,9 +340,10 @@ discard block |
||
| 338 | 340 | /** |
| 339 | 341 | * handle :params(..) |
| 340 | 342 | */ |
| 341 | - if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
|
| 342 | - foreach ($param_indexes[1] as $param_index) { |
|
| 343 | + if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) { |
|
| 344 | + foreach ($param_indexes[1] as $param_index) { |
|
| 343 | 345 | $error_message = str_replace(':params(' . $param_index . ')', $result['params'][$param_index], $error_message); |
| 346 | + } |
|
| 344 | 347 | } |
| 345 | 348 | $error_results[] = str_replace(':attribute', $named_input, $error_message); |
| 346 | 349 | } |
@@ -441,8 +444,9 @@ discard block |
||
| 441 | 444 | */ |
| 442 | 445 | public function has(string $input_name, string $rule_name = null): bool |
| 443 | 446 | { |
| 444 | - if (null !== $rule_name) |
|
| 445 | - return isset($this->errors[$input_name][$rule_name]); |
|
| 447 | + if (null !== $rule_name) { |
|
| 448 | + return isset($this->errors[$input_name][$rule_name]); |
|
| 449 | + } |
|
| 446 | 450 | return isset($this->errors[$input_name]); |
| 447 | 451 | } |
| 448 | 452 | |