@@ -20,9 +20,10 @@ |
||
20 | 20 | { |
21 | 21 | if (mb_strlen($data, 'UTF-8') >= $this->minLength) { |
22 | 22 | return new Result\Success(); |
23 | - } |
|
24 | - else return new Result\Failure( |
|
23 | + } else { |
|
24 | + return new Result\Failure( |
|
25 | 25 | new RuleError(RuleErrorCode::TOO_SHORT, |
26 | 26 | 'The supplied string is too short')); |
27 | + } |
|
27 | 28 | } |
28 | 29 | } |
29 | 30 | \ No newline at end of file |
@@ -22,9 +22,10 @@ |
||
22 | 22 | { |
23 | 23 | if (mb_strlen($data, 'UTF-8') <= $this->maxLength) { |
24 | 24 | return new Success(); |
25 | - } |
|
26 | - else return new Failure( |
|
25 | + } else { |
|
26 | + return new Failure( |
|
27 | 27 | new RuleError(RuleErrorCode::TOO_LONG, |
28 | 28 | 'The supplied string is too long')); |
29 | + } |
|
29 | 30 | } |
30 | 31 | } |
31 | 32 | \ No newline at end of file |
@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | public function getFirstError() : Error |
38 | 38 | { |
39 | - return $this->errors[0]; |
|
39 | + return $this->errors[ 0 ]; |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -7,7 +7,7 @@ |
||
7 | 7 | abstract class Result |
8 | 8 | { |
9 | 9 | private $valid; |
10 | - protected $errors = []; |
|
10 | + protected $errors = [ ]; |
|
11 | 11 | |
12 | 12 | public function __construct(bool $valid, Error... $errors) |
13 | 13 | { |
@@ -39,9 +39,10 @@ |
||
39 | 39 | |
40 | 40 | public function validate($data): Result |
41 | 41 | { |
42 | - if (ctype_alnum(str_replace($this->allowedSpecialChars, '', $data))) |
|
43 | - return new Success(); |
|
44 | - else |
|
45 | - return new Failure(new RuleError(RuleErrorCode::NOT_ALNUM, 'String is not Alphanumeric.')); |
|
42 | + if (ctype_alnum(str_replace($this->allowedSpecialChars, '', $data))) { |
|
43 | + return new Success(); |
|
44 | + } else { |
|
45 | + return new Failure(new RuleError(RuleErrorCode::NOT_ALNUM, 'String is not Alphanumeric.')); |
|
46 | + } |
|
46 | 47 | } |
47 | 48 | } |
48 | 49 | \ No newline at end of file |
@@ -19,13 +19,13 @@ |
||
19 | 19 | * Handy for username validations |
20 | 20 | * @var array $allowedSpecialChars |
21 | 21 | */ |
22 | - protected $allowedSpecialChars = []; |
|
22 | + protected $allowedSpecialChars = [ ]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * AlphaNumeric constructor. |
26 | 26 | * @param array $allowedSpecialChars |
27 | 27 | */ |
28 | - public function __construct($allowedSpecialChars = []) |
|
28 | + public function __construct($allowedSpecialChars = [ ]) |
|
29 | 29 | { |
30 | 30 | $this->allowedSpecialChars = $allowedSpecialChars; |
31 | 31 | } |
@@ -23,9 +23,10 @@ |
||
23 | 23 | { |
24 | 24 | public function validate($data): Result |
25 | 25 | { |
26 | - if (ctype_alpha(str_replace($this->allowedSpecialChars, '', $data))) |
|
27 | - return new Success(); |
|
28 | - else |
|
29 | - return new Failure(new RuleError(RuleErrorCode::NOT_ALPHA, 'String is not Alphabetic.')); |
|
26 | + if (ctype_alpha(str_replace($this->allowedSpecialChars, '', $data))) { |
|
27 | + return new Success(); |
|
28 | + } else { |
|
29 | + return new Failure(new RuleError(RuleErrorCode::NOT_ALPHA, 'String is not Alphabetic.')); |
|
30 | + } |
|
30 | 31 | } |
31 | 32 | } |
32 | 33 | \ No newline at end of file |
@@ -30,9 +30,9 @@ |
||
30 | 30 | /** |
31 | 31 | * @var array $allowedChars |
32 | 32 | */ |
33 | - private $allowedSpecialChars = []; |
|
33 | + private $allowedSpecialChars = [ ]; |
|
34 | 34 | |
35 | - public function __construct(int $minLength = 4, int $maxLength = 12, $allowedSpecialChars = []) |
|
35 | + public function __construct(int $minLength = 4, int $maxLength = 12, $allowedSpecialChars = [ ]) |
|
36 | 36 | { |
37 | 37 | $this->minLength = $minLength; |
38 | 38 | $this->maxLength = $maxLength; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @var array $rules |
26 | 26 | */ |
27 | - private $rules = []; |
|
27 | + private $rules = [ ]; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * ForAll constructor. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * @var Error $errors[] |
50 | 50 | */ |
51 | - $errors = []; |
|
51 | + $errors = [ ]; |
|
52 | 52 | foreach ($this->rules as $rule) { |
53 | 53 | |
54 | 54 | $result = $rule->validate($data); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @var Error $error |
60 | 60 | */ |
61 | 61 | foreach ($result->getErrors() as $error) { |
62 | - $errors[] = $error; |
|
62 | + $errors[ ] = $error; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 |
@@ -33,8 +33,9 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct(Rule... $rules) |
35 | 35 | { |
36 | - if (empty($rules)) |
|
37 | - throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAll::class); |
|
36 | + if (empty($rules)) { |
|
37 | + throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAll::class); |
|
38 | + } |
|
38 | 39 | $this->rules = $rules; |
39 | 40 | } |
40 | 41 | |
@@ -65,9 +66,9 @@ discard block |
||
65 | 66 | |
66 | 67 | } |
67 | 68 | |
68 | - if (!($errors)) |
|
69 | - return new Success(); |
|
70 | - else { |
|
69 | + if (!($errors)) { |
|
70 | + return new Success(); |
|
71 | + } else { |
|
71 | 72 | return new Failure(...$errors); // Use the splat operator |
72 | 73 | |
73 | 74 | } |