@@ -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 | /** |
62 | 62 | * if the key of the $input_rules is numeric that means |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | $rule = $closure; |
67 | 67 | } |
68 | 68 | $rule_and_params = self::getParams($rule); |
69 | - $params = $real_params = $rule_and_params['params']; |
|
70 | - $rule = $rule_and_params['rule']; |
|
69 | + $params = $real_params = $rule_and_params[ 'params' ]; |
|
70 | + $rule = $rule_and_params[ 'rule' ]; |
|
71 | 71 | $params = self::getParamValues($params, $inputs); |
72 | 72 | array_unshift($params, $input_value); |
73 | 73 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | throw new ValidooException(ValidooException::UNKNOWN_RULE, $rule); |
89 | 89 | } |
90 | 90 | if ($validation == false) { |
91 | - $errors[(string)$input][(string)$rule]['result'] = false; |
|
92 | - $errors[(string)$input][(string)$rule]['params'] = $real_params; |
|
91 | + $errors[ (string) $input ][ (string) $rule ][ 'result' ] = false; |
|
92 | + $errors[ (string) $input ][ (string) $rule ][ 'params' ] = $real_params; |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } else { |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | { |
109 | 109 | if (preg_match("#^([\w]+)\((.+?)\)$#", $rule, $matches)) { |
110 | 110 | return [ |
111 | - 'rule' => $matches[1], |
|
112 | - 'params' => explode(',', $matches[2]) |
|
111 | + 'rule' => $matches[ 1 ], |
|
112 | + 'params' => explode(',', $matches[ 2 ]) |
|
113 | 113 | ]; |
114 | 114 | } |
115 | 115 | return [ |
116 | 116 | 'rule' => $rule, |
117 | - 'params' => [] |
|
117 | + 'params' => [ ] |
|
118 | 118 | ]; |
119 | 119 | } |
120 | 120 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | foreach ($params as $key => $param) { |
131 | 131 | if (preg_match("#^:([\w]+)$#", $param, $param_type)) { |
132 | - $params[$key] = @$inputs[(string)$param_type[1]]; |
|
132 | + $params[ $key ] = @$inputs[ (string) $param_type[ 1 ] ]; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | return $params; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected static function integer($input): bool |
170 | 170 | { |
171 | - return is_int($input) || ($input == (string)(int)$input); |
|
171 | + return is_int($input) || ($input == (string) (int) $input); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected static function float($input): bool |
179 | 179 | { |
180 | - return is_float($input) || ($input == (string)(float)$input); |
|
180 | + return is_float($input) || ($input == (string) (float) $input); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | // handle input.rule eg (name.required) |
292 | 292 | if (preg_match("#^(.+?)\.(.+?)$#", $key, $matches)) { |
293 | 293 | // $this->customErrorsWithInputName[name][required] = error message |
294 | - $this->customErrorsWithInputName[(string)$matches[1]][(string)$matches[2]] = $value; |
|
294 | + $this->customErrorsWithInputName[ (string) $matches[ 1 ] ][ (string) $matches[ 2 ] ] = $value; |
|
295 | 295 | } else { |
296 | - $this->customErrors[(string)$key] = $value; |
|
296 | + $this->customErrors[ (string) $key ] = $value; |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | $lang = $this->getDefaultLang(); |
310 | 310 | } |
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,11 +339,11 @@ 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 | 345 | } |
346 | - $error_results[] = str_replace(':attribute', $named_input, $error_message); |
|
346 | + $error_results[ ] = str_replace(':attribute', $named_input, $error_message); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | protected function getDefaultErrorTexts(string $lang = null) |
373 | 373 | { |
374 | 374 | /* handle default error text file */ |
375 | - $default_error_texts = []; |
|
376 | - if (file_exists(__DIR__ . '/errors/' . $lang . '.php')) { |
|
375 | + $default_error_texts = [ ]; |
|
376 | + if (file_exists(__DIR__.'/errors/'.$lang.'.php')) { |
|
377 | 377 | /** @noinspection PhpIncludeInspection */ |
378 | - $default_error_texts = include __DIR__ . '/errors/' . $lang . '.php'; |
|
378 | + $default_error_texts = include __DIR__.'/errors/'.$lang.'.php'; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | return $default_error_texts; |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | protected function getCustomErrorTexts(string $lang = null) |
389 | 389 | { |
390 | 390 | /* handle error text file for custom validators */ |
391 | - $custom_error_texts = []; |
|
391 | + $custom_error_texts = [ ]; |
|
392 | 392 | if (file_exists($this->getErrorFilePath($lang))) { |
393 | 393 | /** @noinspection PhpIncludeInspection */ |
394 | 394 | $custom_error_texts = include $this->getErrorFilePath($lang); |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function handleNaming(string $input_name) |
414 | 414 | { |
415 | - if (isset($this->namings[$input_name])) { |
|
416 | - $named_input = $this->namings[$input_name]; |
|
415 | + if (isset($this->namings[ $input_name ])) { |
|
416 | + $named_input = $this->namings[ $input_name ]; |
|
417 | 417 | } else { |
418 | 418 | $named_input = $input_name; |
419 | 419 | } |
@@ -429,10 +429,10 @@ discard block |
||
429 | 429 | { |
430 | 430 | foreach ($params as $key => $param) { |
431 | 431 | if (preg_match("#^:([\w]+)$#", $param, $param_type)) { |
432 | - if (isset($this->namings[(string)$param_type[1]])) { |
|
433 | - $params[$key] = $this->namings[(string)$param_type[1]]; |
|
432 | + if (isset($this->namings[ (string) $param_type[ 1 ] ])) { |
|
433 | + $params[ $key ] = $this->namings[ (string) $param_type[ 1 ] ]; |
|
434 | 434 | } else { |
435 | - $params[$key] = $param_type[1]; |
|
435 | + $params[ $key ] = $param_type[ 1 ]; |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | } |
@@ -448,10 +448,10 @@ discard block |
||
448 | 448 | public function has(string $input_name, string $rule_name = null): bool |
449 | 449 | { |
450 | 450 | if (null !== $rule_name) { |
451 | - return isset($this->errors[$input_name][$rule_name]); |
|
451 | + return isset($this->errors[ $input_name ][ $rule_name ]); |
|
452 | 452 | } |
453 | 453 | |
454 | - return isset($this->errors[$input_name]); |
|
454 | + return isset($this->errors[ $input_name ]); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |