@@ -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 |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | // handle input.rule eg (name.required) |
56 | 56 | if (preg_match("#^(.+?)\.(.+?)$#", $key, $matches)) { |
57 | 57 | // $this->customErrorsWithInputName[name][required] = error message |
58 | - $this->customErrorsWithInputName[(string)$matches[1]][(string)$matches[2]] = $value; |
|
58 | + $this->customErrorsWithInputName[ (string) $matches[ 1 ] ][ (string) $matches[ 2 ] ] = $value; |
|
59 | 59 | } else { |
60 | - $this->customErrors[(string)$key] = $value; |
|
60 | + $this->customErrors[ (string) $key ] = $value; |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | protected function getDefaultErrorTexts(string $lang = null) |
87 | 87 | { |
88 | 88 | /* handle default error text file */ |
89 | - $default_error_texts = []; |
|
90 | - if (file_exists(__DIR__ . "/errors/" . $lang . ".php")) { |
|
91 | - $default_error_texts = include(__DIR__ . "/errors/" . $lang . ".php"); |
|
89 | + $default_error_texts = [ ]; |
|
90 | + if (file_exists(__DIR__."/errors/".$lang.".php")) { |
|
91 | + $default_error_texts = include(__DIR__."/errors/".$lang.".php"); |
|
92 | 92 | } |
93 | 93 | return $default_error_texts; |
94 | 94 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | protected function getCustomErrorTexts(string $lang = null) |
101 | 101 | { |
102 | 102 | /* handle error text file for custom validators */ |
103 | - $custom_error_texts = []; |
|
103 | + $custom_error_texts = [ ]; |
|
104 | 104 | if (file_exists($this->getErrorFilePath($lang))) { |
105 | 105 | $custom_error_texts = include($this->getErrorFilePath($lang)); |
106 | 106 | } |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function handleNaming(string $input_name) |
115 | 115 | { |
116 | - if (isset($this->namings[$input_name])) { |
|
117 | - $named_input = $this->namings[$input_name]; |
|
116 | + if (isset($this->namings[ $input_name ])) { |
|
117 | + $named_input = $this->namings[ $input_name ]; |
|
118 | 118 | } else { |
119 | 119 | $named_input = $input_name; |
120 | 120 | } |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | { |
130 | 130 | foreach ($params as $key => $param) { |
131 | 131 | if (preg_match("#^:([a-zA-Z0-9_]+)$#", $param, $param_type)) { |
132 | - if (isset($this->namings[(string)$param_type[1]])) { |
|
133 | - $params[$key] = $this->namings[(string)$param_type[1]]; |
|
132 | + if (isset($this->namings[ (string) $param_type[ 1 ] ])) { |
|
133 | + $params[ $key ] = $this->namings[ (string) $param_type[ 1 ] ]; |
|
134 | 134 | } else { |
135 | - $params[$key] = $param_type[1]; |
|
135 | + $params[ $key ] = $param_type[ 1 ]; |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if (null === $lang) |
150 | 150 | $lang = $this->getDefaultLang(); |
151 | 151 | |
152 | - $error_results = []; |
|
152 | + $error_results = [ ]; |
|
153 | 153 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
154 | 154 | $custom_error_texts = $this->getCustomErrorTexts($lang); |
155 | 155 | |
@@ -159,19 +159,19 @@ discard block |
||
159 | 159 | /** |
160 | 160 | * if parameters are input name they should be named as well |
161 | 161 | */ |
162 | - $result['params'] = $this->handleParameterNaming($result['params']); |
|
162 | + $result[ 'params' ] = $this->handleParameterNaming($result[ 'params' ]); |
|
163 | 163 | // if there is a custom message with input name, apply it |
164 | - if (isset($this->customErrorsWithInputName[(string)$input_name][(string)$rule])) { |
|
165 | - $error_message = $this->customErrorsWithInputName[(string)$input_name][(string)$rule]; |
|
164 | + if (isset($this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ])) { |
|
165 | + $error_message = $this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ]; |
|
166 | 166 | } // if there is a custom message for the rule, apply it |
167 | - else if (isset($this->customErrors[(string)$rule])) { |
|
168 | - $error_message = $this->customErrors[(string)$rule]; |
|
167 | + else if (isset($this->customErrors[ (string) $rule ])) { |
|
168 | + $error_message = $this->customErrors[ (string) $rule ]; |
|
169 | 169 | } // if there is a custom validator try to fetch from its error file |
170 | - else if (isset($custom_error_texts[(string)$rule])) { |
|
171 | - $error_message = $custom_error_texts[(string)$rule]; |
|
170 | + else if (isset($custom_error_texts[ (string) $rule ])) { |
|
171 | + $error_message = $custom_error_texts[ (string) $rule ]; |
|
172 | 172 | } // if none try to fetch from default error file |
173 | - else if (isset($default_error_texts[(string)$rule])) { |
|
174 | - $error_message = $default_error_texts[(string)$rule]; |
|
173 | + else if (isset($default_error_texts[ (string) $rule ])) { |
|
174 | + $error_message = $default_error_texts[ (string) $rule ]; |
|
175 | 175 | } else { |
176 | 176 | throw new ValidooException(ValidooException::NO_ERROR_TEXT, $rule); |
177 | 177 | } |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | * handle :params(..) |
180 | 180 | */ |
181 | 181 | if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
182 | - foreach ($param_indexes[1] as $param_index) { |
|
183 | - $error_message = str_replace(":params(" . $param_index . ")", $result['params'][$param_index], $error_message); |
|
182 | + foreach ($param_indexes[ 1 ] as $param_index) { |
|
183 | + $error_message = str_replace(":params(".$param_index.")", $result[ 'params' ][ $param_index ], $error_message); |
|
184 | 184 | } |
185 | - $error_results[] = str_replace(":attribute", $named_input, $error_message); |
|
185 | + $error_results[ ] = str_replace(":attribute", $named_input, $error_message); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | return $error_results; |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | public function has(string $input_name, string $rule_name = null): bool |
197 | 197 | { |
198 | 198 | if (null !== $rule_name) |
199 | - return isset($this->errors[$input_name][$rule_name]); |
|
200 | - return isset($this->errors[$input_name]); |
|
199 | + return isset($this->errors[ $input_name ][ $rule_name ]); |
|
200 | + return isset($this->errors[ $input_name ]); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | { |
218 | 218 | if (preg_match("#^([a-zA-Z0-9_]+)\((.+?)\)$#", $rule, $matches)) { |
219 | 219 | return [ |
220 | - 'rule' => $matches[1], |
|
221 | - 'params' => explode(",", $matches[2]) |
|
220 | + 'rule' => $matches[ 1 ], |
|
221 | + 'params' => explode(",", $matches[ 2 ]) |
|
222 | 222 | ]; |
223 | 223 | } |
224 | 224 | return [ |
225 | 225 | 'rule' => $rule, |
226 | - 'params' => [] |
|
226 | + 'params' => [ ] |
|
227 | 227 | ]; |
228 | 228 | } |
229 | 229 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | { |
238 | 238 | foreach ($params as $key => $param) { |
239 | 239 | if (preg_match("#^:([a-zA-Z0-9_]+)$#", $param, $param_type)) { |
240 | - $params[$key] = @$inputs[(string)$param_type[1]]; |
|
240 | + $params[ $key ] = @$inputs[ (string) $param_type[ 1 ] ]; |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | return $params; |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | foreach ($rules as $input => $input_rules) { |
257 | 257 | if (is_array($input_rules)) { |
258 | 258 | foreach ($input_rules as $rule => $closure) { |
259 | - if (!isset($inputs[(string)$input])) |
|
259 | + if (!isset($inputs[ (string) $input ])) |
|
260 | 260 | $input_value = null; |
261 | 261 | else |
262 | - $input_value = $inputs[(string)$input]; |
|
262 | + $input_value = $inputs[ (string) $input ]; |
|
263 | 263 | /** |
264 | 264 | * if the key of the $input_rules is numeric that means |
265 | 265 | * it's neither an anonymous nor an user function. |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | $rule = $closure; |
269 | 269 | } |
270 | 270 | $rule_and_params = static::getParams($rule); |
271 | - $params = $real_params = $rule_and_params['params']; |
|
272 | - $rule = $rule_and_params['rule']; |
|
271 | + $params = $real_params = $rule_and_params[ 'params' ]; |
|
272 | + $rule = $rule_and_params[ 'rule' ]; |
|
273 | 273 | $params = static::getParamValues($params, $inputs); |
274 | 274 | array_unshift($params, $input_value); |
275 | 275 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | throw new ValidooException(ValidooException::UNKNOWN_RULE, $rule); |
293 | 293 | } |
294 | 294 | if ($validation == false) { |
295 | - $errors[(string)$input][(string)$rule]['result'] = false; |
|
296 | - $errors[(string)$input][(string)$rule]['params'] = $real_params; |
|
295 | + $errors[ (string) $input ][ (string) $rule ][ 'result' ] = false; |
|
296 | + $errors[ (string) $input ][ (string) $rule ][ 'params' ] = $real_params; |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | } else { |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | */ |
337 | 337 | protected static function integer($input): bool |
338 | 338 | { |
339 | - return is_int($input) || ($input == (string)(int)$input); |
|
339 | + return is_int($input) || ($input == (string) (int) $input); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | protected static function float($input): bool |
347 | 347 | { |
348 | - return is_float($input) || ($input == (string)(float)$input); |
|
348 | + return is_float($input) || ($input == (string) (float) $input); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -146,8 +146,9 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getErrors(string $lang = null): array |
148 | 148 | { |
149 | - if (null === $lang) |
|
150 | - $lang = $this->getDefaultLang(); |
|
149 | + if (null === $lang) { |
|
150 | + $lang = $this->getDefaultLang(); |
|
151 | + } |
|
151 | 152 | |
152 | 153 | $error_results = []; |
153 | 154 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
@@ -178,9 +179,10 @@ discard block |
||
178 | 179 | /** |
179 | 180 | * handle :params(..) |
180 | 181 | */ |
181 | - if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
|
182 | - foreach ($param_indexes[1] as $param_index) { |
|
182 | + if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) { |
|
183 | + foreach ($param_indexes[1] as $param_index) { |
|
183 | 184 | $error_message = str_replace(":params(" . $param_index . ")", $result['params'][$param_index], $error_message); |
185 | + } |
|
184 | 186 | } |
185 | 187 | $error_results[] = str_replace(":attribute", $named_input, $error_message); |
186 | 188 | } |
@@ -195,8 +197,9 @@ discard block |
||
195 | 197 | */ |
196 | 198 | public function has(string $input_name, string $rule_name = null): bool |
197 | 199 | { |
198 | - if (null !== $rule_name) |
|
199 | - return isset($this->errors[$input_name][$rule_name]); |
|
200 | + if (null !== $rule_name) { |
|
201 | + return isset($this->errors[$input_name][$rule_name]); |
|
202 | + } |
|
200 | 203 | return isset($this->errors[$input_name]); |
201 | 204 | } |
202 | 205 | |
@@ -256,10 +259,11 @@ discard block |
||
256 | 259 | foreach ($rules as $input => $input_rules) { |
257 | 260 | if (is_array($input_rules)) { |
258 | 261 | foreach ($input_rules as $rule => $closure) { |
259 | - if (!isset($inputs[(string)$input])) |
|
260 | - $input_value = null; |
|
261 | - else |
|
262 | - $input_value = $inputs[(string)$input]; |
|
262 | + if (!isset($inputs[(string)$input])) { |
|
263 | + $input_value = null; |
|
264 | + } else { |
|
265 | + $input_value = $inputs[(string)$input]; |
|
266 | + } |
|
263 | 267 | /** |
264 | 268 | * if the key of the $input_rules is numeric that means |
265 | 269 | * it's neither an anonymous nor an user function. |