@@ -72,7 +72,7 @@ |
||
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @param string $lang |
75 | - * @return null |
|
75 | + * @return string |
|
76 | 76 | */ |
77 | 77 | protected function getErrorFilePath(string $lang) |
78 | 78 | { |
@@ -101,8 +101,9 @@ discard block |
||
101 | 101 | { |
102 | 102 | /* handle error text file for custom validators */ |
103 | 103 | $custom_error_texts = []; |
104 | - if (file_exists($this->getErrorFilePath($lang))) |
|
105 | - $custom_error_texts = include($this->getErrorFilePath($lang)); |
|
104 | + if (file_exists($this->getErrorFilePath($lang))) { |
|
105 | + $custom_error_texts = include($this->getErrorFilePath($lang)); |
|
106 | + } |
|
106 | 107 | return $custom_error_texts; |
107 | 108 | } |
108 | 109 | |
@@ -128,10 +129,11 @@ discard block |
||
128 | 129 | { |
129 | 130 | foreach ($params as $key => $param) { |
130 | 131 | if (preg_match("#^:([a-zA-Z0-9_]+)$#", $param, $param_type)) { |
131 | - if (isset($this->namings[(string)$param_type[1]])) |
|
132 | - $params[$key] = $this->namings[(string)$param_type[1]]; |
|
133 | - else |
|
134 | - $params[$key] = $param_type[1]; |
|
132 | + if (isset($this->namings[(string)$param_type[1]])) { |
|
133 | + $params[$key] = $this->namings[(string)$param_type[1]]; |
|
134 | + } else { |
|
135 | + $params[$key] = $param_type[1]; |
|
136 | + } |
|
135 | 137 | } |
136 | 138 | } |
137 | 139 | return $params; |
@@ -144,8 +146,9 @@ discard block |
||
144 | 146 | */ |
145 | 147 | public function getErrors(string $lang = null): array |
146 | 148 | { |
147 | - if ($lang == null) |
|
148 | - $lang = $this->getDefaultLang(); |
|
149 | + if ($lang == null) { |
|
150 | + $lang = $this->getDefaultLang(); |
|
151 | + } |
|
149 | 152 | |
150 | 153 | $error_results = []; |
151 | 154 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
@@ -175,9 +178,10 @@ discard block |
||
175 | 178 | /** |
176 | 179 | * handle :params(..) |
177 | 180 | */ |
178 | - if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
|
179 | - foreach ($param_indexes[1] as $param_index) { |
|
181 | + if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) { |
|
182 | + foreach ($param_indexes[1] as $param_index) { |
|
180 | 183 | $error_message = str_replace(":params(" . $param_index . ")", $result['params'][$param_index], $error_message); |
184 | + } |
|
181 | 185 | } |
182 | 186 | $error_results[] = str_replace(":attribute", $named_input, $error_message); |
183 | 187 | } |
@@ -192,8 +196,9 @@ discard block |
||
192 | 196 | */ |
193 | 197 | public function has(string $input_name, string $rule_name = null): bool |
194 | 198 | { |
195 | - if ($rule_name != null) |
|
196 | - return isset($this->errors[$input_name][$rule_name]); |
|
199 | + if ($rule_name != null) { |
|
200 | + return isset($this->errors[$input_name][$rule_name]); |
|
201 | + } |
|
197 | 202 | return isset($this->errors[$input_name]); |
198 | 203 | } |
199 | 204 | |
@@ -253,10 +258,11 @@ discard block |
||
253 | 258 | foreach ($rules as $input => $input_rules) { |
254 | 259 | if (is_array($input_rules)) { |
255 | 260 | foreach ($input_rules as $rule => $closure) { |
256 | - if (!isset($inputs[(string)$input])) |
|
257 | - $input_value = null; |
|
258 | - else |
|
259 | - $input_value = $inputs[(string)$input]; |
|
261 | + if (!isset($inputs[(string)$input])) { |
|
262 | + $input_value = null; |
|
263 | + } else { |
|
264 | + $input_value = $inputs[(string)$input]; |
|
265 | + } |
|
260 | 266 | /** |
261 | 267 | * if the key of the $input_rules is numeric that means |
262 | 268 | * it's neither an anonymous nor an user function. |
@@ -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 | return $custom_error_texts; |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function handleNaming(string $input_name) |
114 | 114 | { |
115 | - if (isset($this->namings[$input_name])) { |
|
116 | - $named_input = $this->namings[$input_name]; |
|
115 | + if (isset($this->namings[ $input_name ])) { |
|
116 | + $named_input = $this->namings[ $input_name ]; |
|
117 | 117 | } else { |
118 | 118 | $named_input = $input_name; |
119 | 119 | } |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | { |
129 | 129 | foreach ($params as $key => $param) { |
130 | 130 | if (preg_match("#^:([a-zA-Z0-9_]+)$#", $param, $param_type)) { |
131 | - if (isset($this->namings[(string)$param_type[1]])) |
|
132 | - $params[$key] = $this->namings[(string)$param_type[1]]; |
|
131 | + if (isset($this->namings[ (string) $param_type[ 1 ] ])) |
|
132 | + $params[ $key ] = $this->namings[ (string) $param_type[ 1 ] ]; |
|
133 | 133 | else |
134 | - $params[$key] = $param_type[1]; |
|
134 | + $params[ $key ] = $param_type[ 1 ]; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | return $params; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | if ($lang == null) |
148 | 148 | $lang = $this->getDefaultLang(); |
149 | 149 | |
150 | - $error_results = []; |
|
150 | + $error_results = [ ]; |
|
151 | 151 | $default_error_texts = $this->getDefaultErrorTexts($lang); |
152 | 152 | $custom_error_texts = $this->getCustomErrorTexts($lang); |
153 | 153 | |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | /** |
158 | 158 | * if parameters are input name they should be named as well |
159 | 159 | */ |
160 | - $result['params'] = $this->handleParameterNaming($result['params']); |
|
160 | + $result[ 'params' ] = $this->handleParameterNaming($result[ 'params' ]); |
|
161 | 161 | var_dump($rule); |
162 | 162 | // if there is a custom message with input name, apply it |
163 | - if (isset($this->customErrorsWithInputName[(string)$input_name][(string)$rule])) { |
|
164 | - $error_message = $this->customErrorsWithInputName[(string)$input_name][(string)$rule]; |
|
163 | + if (isset($this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ])) { |
|
164 | + $error_message = $this->customErrorsWithInputName[ (string) $input_name ][ (string) $rule ]; |
|
165 | 165 | } // if there is a custom message for the rule, apply it |
166 | - else if (isset($this->customErrors[(string)$rule])) { |
|
167 | - $error_message = $this->customErrors[(string)$rule]; |
|
166 | + else if (isset($this->customErrors[ (string) $rule ])) { |
|
167 | + $error_message = $this->customErrors[ (string) $rule ]; |
|
168 | 168 | } // if there is a custom validator try to fetch from its error file |
169 | - else if (isset($custom_error_texts[(string)$rule])) { |
|
170 | - $error_message = $custom_error_texts[(string)$rule]; |
|
169 | + else if (isset($custom_error_texts[ (string) $rule ])) { |
|
170 | + $error_message = $custom_error_texts[ (string) $rule ]; |
|
171 | 171 | } // if none try to fetch from default error file |
172 | - else if (isset($default_error_texts[(string)$rule])) { |
|
173 | - $error_message = $default_error_texts[(string)$rule]; |
|
172 | + else if (isset($default_error_texts[ (string) $rule ])) { |
|
173 | + $error_message = $default_error_texts[ (string) $rule ]; |
|
174 | 174 | } else { |
175 | 175 | throw new ValidooException(ValidooException::NO_ERROR_TEXT, $rule); |
176 | 176 | } |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * handle :params(..) |
179 | 179 | */ |
180 | 180 | if (preg_match_all("#:params\((.+?)\)#", $error_message, $param_indexes)) |
181 | - foreach ($param_indexes[1] as $param_index) { |
|
182 | - $error_message = str_replace(":params(" . $param_index . ")", $result['params'][$param_index], $error_message); |
|
181 | + foreach ($param_indexes[ 1 ] as $param_index) { |
|
182 | + $error_message = str_replace(":params(".$param_index.")", $result[ 'params' ][ $param_index ], $error_message); |
|
183 | 183 | } |
184 | - $error_results[] = str_replace(":attribute", $named_input, $error_message); |
|
184 | + $error_results[ ] = str_replace(":attribute", $named_input, $error_message); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | return $error_results; |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | public function has(string $input_name, string $rule_name = null): bool |
196 | 196 | { |
197 | 197 | if ($rule_name != null) |
198 | - return isset($this->errors[$input_name][$rule_name]); |
|
199 | - return isset($this->errors[$input_name]); |
|
198 | + return isset($this->errors[ $input_name ][ $rule_name ]); |
|
199 | + return isset($this->errors[ $input_name ]); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | { |
217 | 217 | if (preg_match("#^([a-zA-Z0-9_]+)\((.+?)\)$#", $rule, $matches)) { |
218 | 218 | return [ |
219 | - 'rule' => $matches[1], |
|
220 | - 'params' => explode(",", $matches[2]) |
|
219 | + 'rule' => $matches[ 1 ], |
|
220 | + 'params' => explode(",", $matches[ 2 ]) |
|
221 | 221 | ]; |
222 | 222 | } |
223 | 223 | return [ |
224 | 224 | 'rule' => $rule, |
225 | - 'params' => [] |
|
225 | + 'params' => [ ] |
|
226 | 226 | ]; |
227 | 227 | } |
228 | 228 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | { |
237 | 237 | foreach ($params as $key => $param) { |
238 | 238 | if (preg_match("#^:([a-zA-Z0-9_]+)$#", $param, $param_type)) { |
239 | - $params[$key] = @$inputs[(string)$param_type[1]]; |
|
239 | + $params[ $key ] = @$inputs[ (string) $param_type[ 1 ] ]; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | return $params; |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | foreach ($rules as $input => $input_rules) { |
256 | 256 | if (is_array($input_rules)) { |
257 | 257 | foreach ($input_rules as $rule => $closure) { |
258 | - if (!isset($inputs[(string)$input])) |
|
258 | + if (!isset($inputs[ (string) $input ])) |
|
259 | 259 | $input_value = null; |
260 | 260 | else |
261 | - $input_value = $inputs[(string)$input]; |
|
261 | + $input_value = $inputs[ (string) $input ]; |
|
262 | 262 | /** |
263 | 263 | * if the key of the $input_rules is numeric that means |
264 | 264 | * it's neither an anonymous nor an user function. |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | $rule = $closure; |
268 | 268 | } |
269 | 269 | $rule_and_params = static::getParams($rule); |
270 | - $params = $real_params = $rule_and_params['params']; |
|
271 | - $rule = $rule_and_params['rule']; |
|
270 | + $params = $real_params = $rule_and_params[ 'params' ]; |
|
271 | + $rule = $rule_and_params[ 'rule' ]; |
|
272 | 272 | $params = static::getParamValues($params, $inputs); |
273 | 273 | array_unshift($params, $input_value); |
274 | 274 | /** |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | throw new ValidooException(ValidooException::UNKNOWN_RULE, $rule); |
292 | 292 | } |
293 | 293 | if ($validation == false) { |
294 | - $errors[(string)$input][(string)$rule]['result'] = false; |
|
295 | - $errors[(string)$input][(string)$rule]['params'] = $real_params; |
|
294 | + $errors[ (string) $input ][ (string) $rule ][ 'result' ] = false; |
|
295 | + $errors[ (string) $input ][ (string) $rule ][ 'params' ] = $real_params; |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 | } else { |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | protected static function integer($input): bool |
337 | 337 | { |
338 | - return is_int($input) || ($input == (string)(int)$input); |
|
338 | + return is_int($input) || ($input == (string) (int) $input); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | protected static function float($input): bool |
346 | 346 | { |
347 | - return is_float($input) || ($input == (string)(float)$input); |
|
347 | + return is_float($input) || ($input == (string) (float) $input); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -20,7 +20,7 @@ |
||
20 | 20 | static::UNKNOWN_RULE => "Unknown Rule: :param", |
21 | 21 | static::ARRAY_EXPECTED => "Rules are expected to Array. Input Name: :param" |
22 | 22 | ); |
23 | - parent::__construct(str_replace(":param", $param, static::$error_messages[$code]), $code); |
|
23 | + parent::__construct(str_replace(":param", $param, static::$error_messages[ $code ]), $code); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | } |