@@ -23,9 +23,10 @@ |
||
23 | 23 | { |
24 | 24 | public function validate($data): Result |
25 | 25 | { |
26 | - if (is_numeric($data)) |
|
27 | - return new Success(); |
|
28 | - else |
|
29 | - return new Failure(new RuleError(RuleErrorCode::NOT_NUMERIC, 'Input value is not numeric')); |
|
26 | + if (is_numeric($data)) { |
|
27 | + return new Success(); |
|
28 | + } else { |
|
29 | + return new Failure(new RuleError(RuleErrorCode::NOT_NUMERIC, 'Input value is not numeric')); |
|
30 | + } |
|
30 | 31 | } |
31 | 32 | } |
32 | 33 | \ No newline at end of file |
@@ -27,12 +27,14 @@ |
||
27 | 27 | { |
28 | 28 | $result = (new StringType())->validate($data); |
29 | 29 | |
30 | - if (!$result->isValid()) |
|
31 | - return new $result; |
|
30 | + if (!$result->isValid()) { |
|
31 | + return new $result; |
|
32 | + } |
|
32 | 33 | |
33 | - if (ctype_alnum(str_replace($this->allowedSpecialChars, '', $data))) |
|
34 | - return new Success(); |
|
35 | - else |
|
36 | - return new Failure(new RuleError(RuleErrorCode::NOT_ALNUM, 'String is not Alphanumeric.')); |
|
34 | + if (ctype_alnum(str_replace($this->allowedSpecialChars, '', $data))) { |
|
35 | + return new Success(); |
|
36 | + } else { |
|
37 | + return new Failure(new RuleError(RuleErrorCode::NOT_ALNUM, 'String is not Alphanumeric.')); |
|
38 | + } |
|
37 | 39 | } |
38 | 40 | } |
39 | 41 | \ 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 | } |
@@ -26,12 +26,14 @@ |
||
26 | 26 | { |
27 | 27 | $result = (new StringType())->validate($data); |
28 | 28 | |
29 | - if (!$result->isValid()) |
|
30 | - return new $result; |
|
29 | + if (!$result->isValid()) { |
|
30 | + return new $result; |
|
31 | + } |
|
31 | 32 | |
32 | - if (ctype_alpha(str_replace($this->allowedSpecialChars, '', $data))) |
|
33 | - return new Success(); |
|
34 | - else |
|
35 | - return new Failure(new RuleError(RuleErrorCode::NOT_ALPHA, 'String is not Alphabetic.')); |
|
33 | + if (ctype_alpha(str_replace($this->allowedSpecialChars, '', $data))) { |
|
34 | + return new Success(); |
|
35 | + } else { |
|
36 | + return new Failure(new RuleError(RuleErrorCode::NOT_ALPHA, 'String is not Alphabetic.')); |
|
37 | + } |
|
36 | 38 | } |
37 | 39 | } |
38 | 40 | \ No newline at end of file |
@@ -27,8 +27,9 @@ |
||
27 | 27 | { |
28 | 28 | $numericResult = (new NumericType())->validate($value); |
29 | 29 | |
30 | - if (!$numericResult->isValid()) |
|
31 | - return new $numericResult; |
|
30 | + if (!$numericResult->isValid()) { |
|
31 | + return new $numericResult; |
|
32 | + } |
|
32 | 33 | |
33 | 34 | if (filter_var(str_replace($this->allowedSpecialChars, '', $value), FILTER_VALIDATE_INT) !== false) { |
34 | 35 | return new Success(); |
@@ -27,8 +27,9 @@ |
||
27 | 27 | { |
28 | 28 | $numericResult = (new NumericType())->validate($value); |
29 | 29 | |
30 | - if (!$numericResult->isValid()) |
|
31 | - return new $numericResult; |
|
30 | + if (!$numericResult->isValid()) { |
|
31 | + return new $numericResult; |
|
32 | + } |
|
32 | 33 | |
33 | 34 | if (filter_var(str_replace($this->allowedSpecialChars, '', $value), FILTER_VALIDATE_FLOAT) !== false) { |
34 | 35 | return new Success(); |
@@ -22,14 +22,16 @@ |
||
22 | 22 | { |
23 | 23 | $result = (new StringType())->validate($data); |
24 | 24 | |
25 | - if (!$result->isValid()) |
|
26 | - return new $result; |
|
25 | + if (!$result->isValid()) { |
|
26 | + return new $result; |
|
27 | + } |
|
27 | 28 | |
28 | 29 | if (mb_strlen($data, 'UTF-8') <= $this->maxLength) { |
29 | 30 | return new Success(); |
30 | - } |
|
31 | - else return new Failure( |
|
31 | + } else { |
|
32 | + return new Failure( |
|
32 | 33 | new RuleError(RuleErrorCode::LENGTH_ERROR, |
33 | 34 | 'The supplied string is too long')); |
35 | + } |
|
34 | 36 | } |
35 | 37 | } |
36 | 38 | \ No newline at end of file |
@@ -20,14 +20,16 @@ |
||
20 | 20 | { |
21 | 21 | $result = (new StringType())->validate($data); |
22 | 22 | |
23 | - if (!$result->isValid()) |
|
24 | - return new $result; |
|
23 | + if (!$result->isValid()) { |
|
24 | + return new $result; |
|
25 | + } |
|
25 | 26 | |
26 | 27 | if (mb_strlen($data, 'UTF-8') >= $this->minLength) { |
27 | 28 | return new Result\Success(); |
28 | - } |
|
29 | - else return new Result\Failure( |
|
29 | + } else { |
|
30 | + return new Result\Failure( |
|
30 | 31 | new RuleError(RuleErrorCode::LENGTH_ERROR, |
31 | 32 | 'The supplied string is too short')); |
33 | + } |
|
32 | 34 | } |
33 | 35 | } |
34 | 36 | \ No newline at end of file |
@@ -35,14 +35,16 @@ |
||
35 | 35 | { |
36 | 36 | $result = (new StringType())->validate($data); |
37 | 37 | |
38 | - if (!$result->isValid()) |
|
39 | - return new $result; |
|
38 | + if (!$result->isValid()) { |
|
39 | + return new $result; |
|
40 | + } |
|
40 | 41 | |
41 | 42 | if (mb_strlen($data, 'UTF-8') == $this->length) { |
42 | 43 | return new Success(); |
43 | - } |
|
44 | - else return new Failure( |
|
44 | + } else { |
|
45 | + return new Failure( |
|
45 | 46 | new RuleError(RuleErrorCode::LENGTH_ERROR, |
46 | 47 | 'The supplied string is not of correct length')); |
48 | + } |
|
47 | 49 | } |
48 | 50 | } |
49 | 51 | \ No newline at end of file |