@@ -11,7 +11,7 @@  | 
                                                    ||
| 11 | 11 | |
| 12 | 12 | abstract class TypeErrorCode  | 
                                                        
| 13 | 13 |  { | 
                                                        
| 14 | - const PREMATURE_CALL_TO_METHOD = 230000;  | 
                                                        |
| 14 | + const PREMATURE_CALL_TO_METHOD = 230000;  | 
                                                        |
| 15 | 15 | |
| 16 | 16 | const EMAIL_INVALID = 320001;  | 
                                                        
| 17 | 17 | const PASSWORD_TOO_SMALL = 320002;  | 
                                                        
@@ -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  | 
                                                        
@@ -90,7 +90,7 @@  | 
                                                    ||
| 90 | 90 |          $containsLower = preg_match('/[a-z]/', $text); | 
                                                        
| 91 | 91 | |
| 92 | 92 | if ($this->strictCheck)  | 
                                                        
| 93 | -           return !preg_match('/[\W]/', $text) && $containsLower; | 
                                                        |
| 93 | +            return !preg_match('/[\W]/', $text) && $containsLower; | 
                                                        |
| 94 | 94 | else  | 
                                                        
| 95 | 95 | return $containsLower;  | 
                                                        
| 96 | 96 | }  | 
                                                        
@@ -44,9 +44,10 @@ discard block  | 
                                                    ||
| 44 | 44 | */  | 
                                                        
| 45 | 45 | public function __construct(int $caseType, bool $allowSpecialChars = true)  | 
                                                        
| 46 | 46 |      { | 
                                                        
| 47 | - if ($caseType > 4 || $caseType < 0)  | 
                                                        |
| 48 | -            throw new \InvalidArgumentException('Case Type ' . $caseType . ' is invalid.  | 
                                                        |
| 47 | +        if ($caseType > 4 || $caseType < 0) { | 
                                                        |
| 48 | +                    throw new \InvalidArgumentException('Case Type ' . $caseType . ' is invalid.  | 
                                                        |
| 49 | 49 | Check the class constants available to be used as caseTypes');  | 
                                                        
| 50 | + }  | 
                                                        |
| 50 | 51 | |
| 51 | 52 | $this->caseType = $caseType;  | 
                                                        
| 52 | 53 | $this->strictCheck = !$allowSpecialChars;  | 
                                                        
@@ -59,10 +60,11 @@ discard block  | 
                                                    ||
| 59 | 60 | private function isMixed(string $text) : bool  | 
                                                        
| 60 | 61 |      { | 
                                                        
| 61 | 62 |          if ($this->strictCheck) { | 
                                                        
| 62 | -            if (preg_match("/^[a-zA-Z]+$/", $text)) | 
                                                        |
| 63 | -                return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); | 
                                                        |
| 64 | - else  | 
                                                        |
| 65 | - return false;  | 
                                                        |
| 63 | +            if (preg_match("/^[a-zA-Z]+$/", $text)) { | 
                                                        |
| 64 | +                            return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); | 
                                                        |
| 65 | +            } else { | 
                                                        |
| 66 | + return false;  | 
                                                        |
| 67 | + }  | 
                                                        |
| 66 | 68 | }  | 
                                                        
| 67 | 69 | |
| 68 | 70 |          return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); | 
                                                        
@@ -70,39 +72,43 @@ discard block  | 
                                                    ||
| 70 | 72 | |
| 71 | 73 | private function isAllUpper(string $text) : bool  | 
                                                        
| 72 | 74 |      { | 
                                                        
| 73 | - if ($this->strictCheck)  | 
                                                        |
| 74 | - return ctype_upper($text);  | 
                                                        |
| 75 | - else  | 
                                                        |
| 76 | -            return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); | 
                                                        |
| 75 | +        if ($this->strictCheck) { | 
                                                        |
| 76 | + return ctype_upper($text);  | 
                                                        |
| 77 | +        } else { | 
                                                        |
| 78 | +                    return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); | 
                                                        |
| 79 | + }  | 
                                                        |
| 77 | 80 | |
| 78 | 81 | }  | 
                                                        
| 79 | 82 | |
| 80 | 83 | private function isAllLower(string $text) : bool  | 
                                                        
| 81 | 84 |      { | 
                                                        
| 82 | - if ($this->strictCheck)  | 
                                                        |
| 83 | - return ctype_lower($text);  | 
                                                        |
| 84 | - else  | 
                                                        |
| 85 | -            return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); | 
                                                        |
| 85 | +        if ($this->strictCheck) { | 
                                                        |
| 86 | + return ctype_lower($text);  | 
                                                        |
| 87 | +        } else { | 
                                                        |
| 88 | +                    return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); | 
                                                        |
| 89 | + }  | 
                                                        |
| 86 | 90 | }  | 
                                                        
| 87 | 91 | |
| 88 | 92 | private function isSomeLower(string $text) : bool  | 
                                                        
| 89 | 93 |      { | 
                                                        
| 90 | 94 |          $containsLower = preg_match('/[a-z]/', $text); | 
                                                        
| 91 | 95 | |
| 92 | - if ($this->strictCheck)  | 
                                                        |
| 93 | -           return !preg_match('/[\W]/', $text) && $containsLower; | 
                                                        |
| 94 | - else  | 
                                                        |
| 95 | - return $containsLower;  | 
                                                        |
| 96 | +        if ($this->strictCheck) { | 
                                                        |
| 97 | +                   return !preg_match('/[\W]/', $text) && $containsLower; | 
                                                        |
| 98 | +        } else { | 
                                                        |
| 99 | + return $containsLower;  | 
                                                        |
| 100 | + }  | 
                                                        |
| 96 | 101 | }  | 
                                                        
| 97 | 102 | |
| 98 | 103 | private function isSomeUpper(string $text) : bool  | 
                                                        
| 99 | 104 |      { | 
                                                        
| 100 | 105 |          $containsUpper = preg_match('/[A-Z]/', $text); | 
                                                        
| 101 | 106 | |
| 102 | - if ($this->strictCheck)  | 
                                                        |
| 103 | -            return !preg_match('/[\W]/', $text) && $containsUpper; | 
                                                        |
| 104 | - else  | 
                                                        |
| 105 | - return $containsUpper;  | 
                                                        |
| 107 | +        if ($this->strictCheck) { | 
                                                        |
| 108 | +                    return !preg_match('/[\W]/', $text) && $containsUpper; | 
                                                        |
| 109 | +        } else { | 
                                                        |
| 110 | + return $containsUpper;  | 
                                                        |
| 111 | + }  | 
                                                        |
| 106 | 112 | }  | 
                                                        
| 107 | 113 | |
| 108 | 114 | public function validate($data): Result  | 
                                                        
@@ -127,10 +133,11 @@ discard block  | 
                                                    ||
| 127 | 133 | break;  | 
                                                        
| 128 | 134 | }  | 
                                                        
| 129 | 135 | |
| 130 | - if ($isValid)  | 
                                                        |
| 131 | - return new Success();  | 
                                                        |
| 132 | - else  | 
                                                        |
| 133 | - return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH,  | 
                                                        |
| 136 | +        if ($isValid) { | 
                                                        |
| 137 | + return new Success();  | 
                                                        |
| 138 | +        } else { | 
                                                        |
| 139 | + return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH,  | 
                                                        |
| 134 | 140 | "The given string doesn't match the required case"));  | 
                                                        
| 141 | + }  | 
                                                        |
| 135 | 142 | }  | 
                                                        
| 136 | 143 | }  | 
                                                        
| 137 | 144 | \ 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  |