@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * AlphaNumeric constructor. |
| 33 | 33 | * @param array $allowedSpecialChars |
| 34 | 34 | */ |
| 35 | - public function __construct($allowedSpecialChars = []) |
|
| 35 | + public function __construct($allowedSpecialChars = [ ]) |
|
| 36 | 36 | { |
| 37 | 37 | $this->allowedSpecialChars = $allowedSpecialChars; |
| 38 | 38 | } |
@@ -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 |
@@ -42,9 +42,10 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function __construct(int $caseType, bool $strictCheck = false) |
| 44 | 44 | { |
| 45 | - if ($caseType > 2 || $caseType < 0) |
|
| 46 | - throw new \InvalidArgumentException('Case Type ' . $caseType . ' is invalid. |
|
| 45 | + if ($caseType > 2 || $caseType < 0) { |
|
| 46 | + throw new \InvalidArgumentException('Case Type ' . $caseType . ' is invalid. |
|
| 47 | 47 | Check the class constants available to be used as caseTypes'); |
| 48 | + } |
|
| 48 | 49 | |
| 49 | 50 | $this->caseType = $caseType; |
| 50 | 51 | $this->strictCheck = $strictCheck; |
@@ -57,10 +58,11 @@ discard block |
||
| 57 | 58 | private function isMixed(string $text) : bool |
| 58 | 59 | { |
| 59 | 60 | if ($this->strictCheck) { |
| 60 | - if (preg_match("/^[a-zA-Z]+$/", $text)) |
|
| 61 | - return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 62 | - else |
|
| 63 | - return false; |
|
| 61 | + if (preg_match("/^[a-zA-Z]+$/", $text)) { |
|
| 62 | + return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 63 | + } else { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
@@ -68,19 +70,21 @@ discard block |
||
| 68 | 70 | |
| 69 | 71 | private function isAllCaps(string $text) : bool |
| 70 | 72 | { |
| 71 | - if ($this->strictCheck) |
|
| 72 | - return ctype_upper($text); |
|
| 73 | - else |
|
| 74 | - return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 73 | + if ($this->strictCheck) { |
|
| 74 | + return ctype_upper($text); |
|
| 75 | + } else { |
|
| 76 | + return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 77 | + } |
|
| 75 | 78 | |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | 81 | private function isNoneCaps(string $text) : bool |
| 79 | 82 | { |
| 80 | - if ($this->strictCheck) |
|
| 81 | - return ctype_lower($text); |
|
| 82 | - else |
|
| 83 | - return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
| 83 | + if ($this->strictCheck) { |
|
| 84 | + return ctype_lower($text); |
|
| 85 | + } else { |
|
| 86 | + return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
| 87 | + } |
|
| 84 | 88 | } |
| 85 | 89 | |
| 86 | 90 | public function validate($data): Result |
@@ -100,10 +104,11 @@ discard block |
||
| 100 | 104 | break; |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | - if ($isValid) |
|
| 104 | - return new Success(); |
|
| 105 | - else |
|
| 106 | - return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
| 107 | + if ($isValid) { |
|
| 108 | + return new Success(); |
|
| 109 | + } else { |
|
| 110 | + return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
| 107 | 111 | "The given string doesn't match the required case")); |
| 112 | + } |
|
| 108 | 113 | } |
| 109 | 114 | } |
| 110 | 115 | \ No newline at end of file |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | |
| 12 | 12 | class IPAddressValidator implements Validator |
| 13 | 13 | { |
| 14 | - public function validate($type, $options = []): Result |
|
| 14 | + public function validate($type, $options = [ ]): Result |
|
| 15 | 15 | { |
| 16 | 16 | if (filter_var($type, FILTER_VALIDATE_IP)) { |
| 17 | 17 | return new Success(); |