@@ -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 | } |
@@ -44,12 +44,14 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function __construct(int $numOfRules, Rule... $rules) |
| 46 | 46 | { |
| 47 | - if (empty($rules)) |
|
| 48 | - throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAtLeast::class); |
|
| 47 | + if (empty($rules)) { |
|
| 48 | + throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAtLeast::class); |
|
| 49 | + } |
|
| 49 | 50 | |
| 50 | - if (count($rules) < $numOfRules) |
|
| 51 | - throw new InvalidAggregateRule('Minimum passing rule number is greater than supplied rules', |
|
| 51 | + if (count($rules) < $numOfRules) { |
|
| 52 | + throw new InvalidAggregateRule('Minimum passing rule number is greater than supplied rules', |
|
| 52 | 53 | ForAtLeast::class); |
| 54 | + } |
|
| 53 | 55 | |
| 54 | 56 | $this->rules = $rules; |
| 55 | 57 | $this->minimum = $numOfRules; |
@@ -74,13 +76,13 @@ discard block |
||
| 74 | 76 | foreach ($result->getErrors() as $error) { |
| 75 | 77 | $errors[] = $error; |
| 76 | 78 | } |
| 77 | - } |
|
| 78 | - else { |
|
| 79 | + } else { |
|
| 79 | 80 | $passed++; |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | - if ($passed >= $this->minimum) |
|
| 83 | - return new Success(); |
|
| 83 | + if ($passed >= $this->minimum) { |
|
| 84 | + return new Success(); |
|
| 85 | + } |
|
| 84 | 86 | } |
| 85 | 87 | return new Failure(...$errors); |
| 86 | 88 | } |
@@ -39,8 +39,9 @@ |
||
| 39 | 39 | |
| 40 | 40 | $result = $rule->validate($password); |
| 41 | 41 | |
| 42 | - if ($result->isValid()) |
|
| 43 | - return new Success(); |
|
| 42 | + if ($result->isValid()) { |
|
| 43 | + return new Success(); |
|
| 44 | + } |
|
| 44 | 45 | /** |
| 45 | 46 | * @var Failure $result |
| 46 | 47 | */ |
@@ -38,8 +38,9 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function __construct(int $patternType) |
| 40 | 40 | { |
| 41 | - if ($patternType < 0 || $patternType > 3) |
|
| 42 | - throw new InvalidRuleOption($patternType); |
|
| 41 | + if ($patternType < 0 || $patternType > 3) { |
|
| 42 | + throw new InvalidRuleOption($patternType); |
|
| 43 | + } |
|
| 43 | 44 | |
| 44 | 45 | $this->pattern = $patternType; |
| 45 | 46 | } |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | break; |
| 64 | 65 | } |
| 65 | 66 | |
| 66 | - if ($isValid) |
|
| 67 | - return new Success(); |
|
| 68 | - else |
|
| 69 | - return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, |
|
| 67 | + if ($isValid) { |
|
| 68 | + return new Success(); |
|
| 69 | + } else { |
|
| 70 | + return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, |
|
| 70 | 71 | "The string doesn't contain the required pattern")); |
| 72 | + } |
|
| 71 | 73 | } |
| 72 | 74 | } |
| 73 | 75 | \ No newline at end of file |
@@ -33,9 +33,10 @@ |
||
| 33 | 33 | |
| 34 | 34 | public function validate($data): Result |
| 35 | 35 | { |
| 36 | - if (strpos($data, $this->keyword) !== false) |
|
| 37 | - return new Success(); |
|
| 38 | - else |
|
| 39 | - return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, "String does not contain keyword")); |
|
| 36 | + if (strpos($data, $this->keyword) !== false) { |
|
| 37 | + return new Success(); |
|
| 38 | + } else { |
|
| 39 | + return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, "String does not contain keyword")); |
|
| 40 | + } |
|
| 40 | 41 | } |
| 41 | 42 | } |
| 42 | 43 | \ No newline at end of file |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | $containsLower = (bool) preg_match('/[a-z]/', $text); |
| 92 | 92 | |
| 93 | 93 | if ($this->strictCheck) |
| 94 | - return !preg_match('/[\W]/', $text) && $containsLower; |
|
| 94 | + return !preg_match('/[\W]/', $text) && $containsLower; |
|
| 95 | 95 | else |
| 96 | 96 | return $containsLower; |
| 97 | 97 | } |
@@ -47,8 +47,9 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct(int $caseType, bool $allowSpecialChars = true) |
| 49 | 49 | { |
| 50 | - if ($caseType > 4 || $caseType < 0) |
|
| 51 | - throw new InvalidRuleOption($caseType, TextCase::class); |
|
| 50 | + if ($caseType > 4 || $caseType < 0) { |
|
| 51 | + throw new InvalidRuleOption($caseType, TextCase::class); |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | $this->caseType = $caseType; |
| 54 | 55 | $this->strictCheck = !$allowSpecialChars; |
@@ -61,10 +62,11 @@ discard block |
||
| 61 | 62 | private function isMixed(string $text) : bool |
| 62 | 63 | { |
| 63 | 64 | if ($this->strictCheck) { |
| 64 | - if (preg_match("/^[a-zA-Z]+$/", $text)) |
|
| 65 | - return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 66 | - else |
|
| 67 | - return false; |
|
| 65 | + if (preg_match("/^[a-zA-Z]+$/", $text)) { |
|
| 66 | + return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 68 | 70 | } |
| 69 | 71 | |
| 70 | 72 | return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
@@ -72,47 +74,52 @@ discard block |
||
| 72 | 74 | |
| 73 | 75 | private function isAllUpper(string $text) : bool |
| 74 | 76 | { |
| 75 | - if ($this->strictCheck) |
|
| 76 | - return ctype_upper($text); |
|
| 77 | - else |
|
| 78 | - return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 77 | + if ($this->strictCheck) { |
|
| 78 | + return ctype_upper($text); |
|
| 79 | + } else { |
|
| 80 | + return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
| 81 | + } |
|
| 79 | 82 | |
| 80 | 83 | } |
| 81 | 84 | |
| 82 | 85 | private function isAllLower(string $text) : bool |
| 83 | 86 | { |
| 84 | - if ($this->strictCheck) |
|
| 85 | - return ctype_lower($text); |
|
| 86 | - else |
|
| 87 | - return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
| 87 | + if ($this->strictCheck) { |
|
| 88 | + return ctype_lower($text); |
|
| 89 | + } else { |
|
| 90 | + return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
| 91 | + } |
|
| 88 | 92 | } |
| 89 | 93 | |
| 90 | 94 | private function isSomeLower(string $text) : bool |
| 91 | 95 | { |
| 92 | 96 | $containsLower = (bool) preg_match('/[a-z]/', $text); |
| 93 | 97 | |
| 94 | - if ($this->strictCheck) |
|
| 95 | - return !preg_match('/[\W]/', $text) && $containsLower; |
|
| 96 | - else |
|
| 97 | - return $containsLower; |
|
| 98 | + if ($this->strictCheck) { |
|
| 99 | + return !preg_match('/[\W]/', $text) && $containsLower; |
|
| 100 | + } else { |
|
| 101 | + return $containsLower; |
|
| 102 | + } |
|
| 98 | 103 | } |
| 99 | 104 | |
| 100 | 105 | private function isSomeUpper(string $text) : bool |
| 101 | 106 | { |
| 102 | 107 | $containsUpper = (bool) preg_match('/[A-Z]/', $text); |
| 103 | 108 | |
| 104 | - if ($this->strictCheck) |
|
| 105 | - return !preg_match('/[\W]/', $text) && $containsUpper; |
|
| 106 | - else |
|
| 107 | - return $containsUpper; |
|
| 109 | + if ($this->strictCheck) { |
|
| 110 | + return !preg_match('/[\W]/', $text) && $containsUpper; |
|
| 111 | + } else { |
|
| 112 | + return $containsUpper; |
|
| 113 | + } |
|
| 108 | 114 | } |
| 109 | 115 | |
| 110 | 116 | public function validate($data): Result |
| 111 | 117 | { |
| 112 | 118 | $result = (new StringType())->validate($data); |
| 113 | 119 | |
| 114 | - if (!$result->isValid()) |
|
| 115 | - return new $result; |
|
| 120 | + if (!$result->isValid()) { |
|
| 121 | + return new $result; |
|
| 122 | + } |
|
| 116 | 123 | |
| 117 | 124 | $isValid = false; |
| 118 | 125 | |
@@ -134,10 +141,11 @@ discard block |
||
| 134 | 141 | break; |
| 135 | 142 | } |
| 136 | 143 | |
| 137 | - if ($isValid) |
|
| 138 | - return new Success(); |
|
| 139 | - else |
|
| 140 | - return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
| 144 | + if ($isValid) { |
|
| 145 | + return new Success(); |
|
| 146 | + } else { |
|
| 147 | + return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
| 141 | 148 | "The given string doesn't match the required case")); |
| 149 | + } |
|
| 142 | 150 | } |
| 143 | 151 | } |
| 144 | 152 | \ No newline at end of file |
@@ -66,8 +66,9 @@ |
||
| 66 | 66 | |
| 67 | 67 | $result = $rule->validate($name); |
| 68 | 68 | |
| 69 | - if ($result->isValid()) |
|
| 70 | - return new Success(); |
|
| 69 | + if ($result->isValid()) { |
|
| 70 | + return new Success(); |
|
| 71 | + } |
|
| 71 | 72 | /** |
| 72 | 73 | * @var Failure $result |
| 73 | 74 | */ |
@@ -36,11 +36,13 @@ |
||
| 36 | 36 | { |
| 37 | 37 | $numericResult = (new NumericType())->validate($value); |
| 38 | 38 | |
| 39 | - if (!$numericResult->isValid()) |
|
| 40 | - return new $numericResult; |
|
| 39 | + if (!$numericResult->isValid()) { |
|
| 40 | + return new $numericResult; |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | - if ($value == $this->expected) |
|
| 43 | - return new Success(); |
|
| 43 | + if ($value == $this->expected) { |
|
| 44 | + return new Success(); |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | return new Failure(new RuleError(RuleErrorCode::LESS_THAN_MINIMUM, |
| 46 | 48 | 'The supplied number is less than the expectedimum value')); |
@@ -36,11 +36,13 @@ |
||
| 36 | 36 | { |
| 37 | 37 | $numericResult = (new NumericType())->validate($value); |
| 38 | 38 | |
| 39 | - if (!$numericResult->isValid()) |
|
| 40 | - return new $numericResult; |
|
| 39 | + if (!$numericResult->isValid()) { |
|
| 40 | + return new $numericResult; |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | - if ($value >= $this->min) |
|
| 43 | - return new Success(); |
|
| 43 | + if ($value >= $this->min) { |
|
| 44 | + return new Success(); |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | return new Failure(new RuleError(RuleErrorCode::LESS_THAN_MINIMUM, |
| 46 | 48 | 'The supplied number is less than the minimum value')); |