@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function validateAccept($field, $value, array $parameters, Validator $validator) |
23 | 23 | { |
24 | - return in_array(strtolower($value), ['yes', 'on', '1', 1, true], true); |
|
24 | + return in_array(strtolower($value), [ 'yes', 'on', '1', 1, true ], true); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function validateSize($field, $value, array $parameters, Validator $validator) |
75 | 75 | { |
76 | - $size = filter_var($parameters[0], FILTER_VALIDATE_INT); |
|
77 | - false === $size && $size = filter_var($parameters[0], FILTER_VALIDATE_FLOAT); |
|
76 | + $size = filter_var($parameters[ 0 ], FILTER_VALIDATE_INT); |
|
77 | + false === $size && $size = filter_var($parameters[ 0 ], FILTER_VALIDATE_FLOAT); |
|
78 | 78 | |
79 | 79 | return $this->getSize($field, $value) === $size; |
80 | 80 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function validateBoolean($field, $value, array $parameters, Validator $validator) |
104 | 104 | { |
105 | - return in_array($value, [true, false, 0, 1, '0', '1'], true); |
|
105 | + return in_array($value, [ true, false, 0, 1, '0', '1' ], true); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function validateConfirm($field, $value, array $parameters, Validator $validator) |
117 | 117 | { |
118 | - return $value === $this->data[$parameters[0]]; |
|
118 | + return $value === $this->data[ $parameters[ 0 ] ]; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function validateRequiredWith($field, $value, array $parameters, Validator $validator) |
171 | 171 | { |
172 | - return !is_null($value) || !array_key_exists($parameters[0], $this->data); |
|
172 | + return !is_null($value) || !array_key_exists($parameters[ 0 ], $this->data); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function validateRequiredWithout($field, $value, array $parameters, Validator $validator) |
184 | 184 | { |
185 | - return !is_null($value) || array_key_exists($parameters[0], $this->data); |
|
185 | + return !is_null($value) || array_key_exists($parameters[ 0 ], $this->data); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $otherField = array_shift($parameters); |
199 | 199 | |
200 | 200 | return !is_null($value) || ( |
201 | - !array_key_exists($otherField, $this->data) || false === array_search($this->data[$otherField], $parameters) |
|
201 | + !array_key_exists($otherField, $this->data) || false === array_search($this->data[ $otherField ], $parameters) |
|
202 | 202 | ); |
203 | 203 | } |
204 | 204 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $otherField = array_shift($parameters); |
216 | 216 | |
217 | 217 | return !is_null($value) || ( |
218 | - !array_key_exists($otherField, $this->data) || false !== array_search($this->data[$otherField], $parameters) |
|
218 | + !array_key_exists($otherField, $this->data) || false !== array_search($this->data[ $otherField ], $parameters) |
|
219 | 219 | ); |
220 | 220 | } |
221 | 221 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function validateMin($field, $value, array $parameters, Validator $validator) |
269 | 269 | { |
270 | - return $this->getSize($field, $value) >= $parameters[0]; |
|
270 | + return $this->getSize($field, $value) >= $parameters[ 0 ]; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function validateMax($field, $value, array $parameters, Validator $validator) |
282 | 282 | { |
283 | - return $this->getSize($field, $value) <= $parameters[0]; |
|
283 | + return $this->getSize($field, $value) <= $parameters[ 0 ]; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -294,25 +294,25 @@ discard block |
||
294 | 294 | public function validateRange($field, $value, array $parameters, Validator $validator) |
295 | 295 | { |
296 | 296 | $size = $this->getSize($field, $value); |
297 | - if (!isset($parameters[0])) { |
|
297 | + if (!isset($parameters[ 0 ])) { |
|
298 | 298 | return false; |
299 | 299 | } |
300 | - if (isset($parameters[1])) { |
|
301 | - if ('' === $parameters[0]) { |
|
302 | - if ('' === $parameters[1]) { |
|
300 | + if (isset($parameters[ 1 ])) { |
|
301 | + if ('' === $parameters[ 0 ]) { |
|
302 | + if ('' === $parameters[ 1 ]) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | |
306 | - return $size <= $parameters[1]; |
|
306 | + return $size <= $parameters[ 1 ]; |
|
307 | 307 | } |
308 | - if ('' === $parameters[1]) { |
|
309 | - return $size >= $parameters[0]; |
|
308 | + if ('' === $parameters[ 1 ]) { |
|
309 | + return $size >= $parameters[ 0 ]; |
|
310 | 310 | } |
311 | 311 | |
312 | - return $size >= $parameters[0] && $size <= $parameters[1]; |
|
312 | + return $size >= $parameters[ 0 ] && $size <= $parameters[ 1 ]; |
|
313 | 313 | } |
314 | 314 | |
315 | - return '' === $parameters[0] ? false : ($size >= $parameters[0]); |
|
315 | + return '' === $parameters[ 0 ] ? false : ($size >= $parameters[ 0 ]); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | */ |
326 | 326 | public function validateRegex($field, $value, array $parameters, Validator $validator) |
327 | 327 | { |
328 | - return (bool) preg_match($parameters[0], $value); |
|
328 | + return (bool) preg_match($parameters[ 0 ], $value); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | */ |
365 | 365 | public function validateDateFormat($field, $value, array $parameters, Validator $validator) |
366 | 366 | { |
367 | - return !(bool) date_parse_from_format($parameters[0], $value)['error_count']; |
|
367 | + return !(bool) date_parse_from_format($parameters[ 0 ], $value)[ 'error_count' ]; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function validateDateBefore($field, $value, array $parameters, Validator $validator) |
379 | 379 | { |
380 | - return strtotime($value) < strtotime($parameters[0]); |
|
380 | + return strtotime($value) < strtotime($parameters[ 0 ]); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | */ |
391 | 391 | public function validateDateAfter($field, $value, array $parameters, Validator $validator) |
392 | 392 | { |
393 | - return strtotime($value) > strtotime($parameters[0]); |
|
393 | + return strtotime($value) > strtotime($parameters[ 0 ]); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | { |
419 | 419 | $specifyField = array_shift($parameters); |
420 | 420 | |
421 | - return array_key_exists($specifyField, $this->data) && $value !== $this->data[$specifyField]; |
|
421 | + return array_key_exists($specifyField, $this->data) && $value !== $this->data[ $specifyField ]; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | public function getSize($field, $value) |
431 | 431 | { |
432 | 432 | switch (true) { |
433 | - case isset($this->ruleGroups[$field]['String']) && is_string($value): |
|
433 | + case isset($this->ruleGroups[ $field ][ 'String' ]) && is_string($value): |
|
434 | 434 | return strlen($value); |
435 | 435 | case is_array($value): |
436 | 436 | return count($value); |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | |
12 | 12 | trait MessagesAttributes |
13 | 13 | { |
14 | - protected $templates = []; |
|
14 | + protected $templates = [ ]; |
|
15 | 15 | |
16 | - protected function loadMessageTemplate($file, array $customMessage = []) |
|
16 | + protected function loadMessageTemplate($file, array $customMessage = [ ]) |
|
17 | 17 | { |
18 | 18 | $this->templates = require $file; |
19 | 19 | $this->templates = array_merge($this->templates, self::$extensionTemplates); |
20 | 20 | |
21 | 21 | foreach ($customMessage as $rule => $template) { |
22 | - $this->templates[self::formatRuleName($rule)] = $template; |
|
22 | + $this->templates[ self::formatRuleName($rule) ] = $template; |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - protected function buildMessage($rule, $field, array $parameters = []) |
|
33 | + protected function buildMessage($rule, $field, array $parameters = [ ]) |
|
34 | 34 | { |
35 | - if (!isset($this->templates[$rule])) { |
|
35 | + if (!isset($this->templates[ $rule ])) { |
|
36 | 36 | return "{$field} field check failed"; |
37 | 37 | } |
38 | - array_unshift($parameters, "{$field} {$this->templates[$rule]}"); |
|
38 | + array_unshift($parameters, "{$field} {$this->templates[ $rule ]}"); |
|
39 | 39 | |
40 | 40 | try { |
41 | 41 | return sprintf(...$parameters); |
@@ -21,32 +21,32 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @var array |
23 | 23 | */ |
24 | - protected $data = []; |
|
24 | + protected $data = [ ]; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @var array |
28 | 28 | */ |
29 | - protected $ruleGroups = []; |
|
29 | + protected $ruleGroups = [ ]; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @var array |
33 | 33 | */ |
34 | - protected $messages = []; |
|
34 | + protected $messages = [ ]; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var array |
38 | 38 | */ |
39 | - protected static $forceRules = ['Required', 'RequiredIf', 'RequiredWith', 'RequiredUnless', 'RequiredWithout']; |
|
39 | + protected static $forceRules = [ 'Required', 'RequiredIf', 'RequiredWith', 'RequiredUnless', 'RequiredWithout' ]; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var array |
43 | 43 | */ |
44 | - protected static $extensions = []; |
|
44 | + protected static $extensions = [ ]; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var array |
48 | 48 | */ |
49 | - protected static $extensionTemplates = []; |
|
49 | + protected static $extensionTemplates = [ ]; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Validator constructor. |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param array $customMessages |
57 | 57 | * @param string $file |
58 | 58 | */ |
59 | - public function __construct(array $data, array $rules, array $customMessages = [], $file = __DIR__.'/messages/en.php') |
|
59 | + public function __construct(array $data, array $rules, array $customMessages = [ ], $file = __DIR__.'/messages/en.php') |
|
60 | 60 | { |
61 | 61 | $this->data = $data; |
62 | 62 | $this->parseRules($rules); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | { |
74 | 74 | $name = self::formatRuleName($name); |
75 | 75 | |
76 | - self::$extensions[$name] = $callback; |
|
76 | + self::$extensions[ $name ] = $callback; |
|
77 | 77 | |
78 | - $isForce && self::$forceRules[] = $name; |
|
78 | + $isForce && self::$forceRules[ ] = $name; |
|
79 | 79 | |
80 | - !empty($message) && (static::$extensionTemplates[$name] = $message); |
|
80 | + !empty($message) && (static::$extensionTemplates[ $name ] = $message); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | $value = $this->getField($field); |
91 | 91 | foreach ($rules as $rule => $parameters) { |
92 | 92 | if (!$this->runValidateRule($rule, $field, $value, $parameters)) { |
93 | - $this->messages[$field][$rule] = $this->buildMessage($rule, $field, $parameters); |
|
93 | + $this->messages[ $field ][ $rule ] = $this->buildMessage($rule, $field, $parameters); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | } elseif ($forceRules = array_intersect(self::$forceRules, array_keys($rules))) { |
97 | 97 | foreach ($forceRules as $rule) { |
98 | - if (!$this->runValidateRule($rule, $field, null, $rules[$rule])) { |
|
99 | - $this->messages[$field][$rule] = $this->buildMessage($rule, $field, $rules[$rule]); |
|
98 | + if (!$this->runValidateRule($rule, $field, null, $rules[ $rule ])) { |
|
99 | + $this->messages[ $field ][ $rule ] = $this->buildMessage($rule, $field, $rules[ $rule ]); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function parseRules(array $ruleGroups) |
136 | 136 | { |
137 | - $map = []; |
|
137 | + $map = [ ]; |
|
138 | 138 | foreach ($ruleGroups as $field => $rules) { |
139 | 139 | foreach (explode('|', $rules) as $rule) { |
140 | 140 | list($rule, $parameters) = explode(':', (false === strpos($rule, ':') ? ($rule.':') : $rule), 2); |
141 | - !isset($map[$rule]) && $map[$rule] = self::formatRuleName($rule); |
|
142 | - $rule = $map[$rule]; |
|
143 | - $this->ruleGroups[$field][$rule] = ('' === $parameters ? [] : explode(',', $parameters)); |
|
141 | + !isset($map[ $rule ]) && $map[ $rule ] = self::formatRuleName($rule); |
|
142 | + $rule = $map[ $rule ]; |
|
143 | + $this->ruleGroups[ $field ][ $rule ] = ('' === $parameters ? [ ] : explode(',', $parameters)); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | return implode( |
156 | 156 | '', |
157 | 157 | array_map( |
158 | - function ($value) { |
|
158 | + function($value) { |
|
159 | 159 | return ucfirst($value); |
160 | 160 | }, |
161 | 161 | explode('_', $name) |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | if (!array_key_exists($item, $this->data)) { |
176 | 176 | return false; |
177 | 177 | } |
178 | - $value = $this->data[$item]; |
|
178 | + $value = $this->data[ $item ]; |
|
179 | 179 | |
180 | 180 | foreach ($field as $item) { |
181 | 181 | if (!array_key_exists($item, $value)) { |
182 | 182 | return false; |
183 | 183 | } |
184 | - $value = $value[$item]; |
|
184 | + $value = $value[ $item ]; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | return true; |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | { |
197 | 197 | $field = explode('.', $field); |
198 | 198 | $item = array_shift($field); |
199 | - $value = $this->data[$item]; |
|
199 | + $value = $this->data[ $item ]; |
|
200 | 200 | foreach ($field as $item) { |
201 | - $value = $value[$item]; |
|
201 | + $value = $value[ $item ]; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | return $value; |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @return bool |
214 | 214 | */ |
215 | - protected function runValidateRule($rule, $field, $value, array $parameters = []) |
|
215 | + protected function runValidateRule($rule, $field, $value, array $parameters = [ ]) |
|
216 | 216 | { |
217 | - $callback = array_key_exists($rule, self::$extensions) ? self::$extensions[$rule] : [$this, "validate{$rule}"]; |
|
217 | + $callback = array_key_exists($rule, self::$extensions) ? self::$extensions[ $rule ] : [ $this, "validate{$rule}" ]; |
|
218 | 218 | |
219 | 219 | return (bool) call_user_func($callback, $field, $value, $parameters, $this); |
220 | 220 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | { |
224 | 224 | $rule = self::formatRuleName(substr($method, 8)); |
225 | 225 | |
226 | - if (!isset(self::$extensions[$rule])) { |
|
226 | + if (!isset(self::$extensions[ $rule ])) { |
|
227 | 227 | throw new BadMethodCallException(sprintf('Method %s::%s does not exists', static::class, $method)); |
228 | 228 | } |
229 | 229 |