@@ -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 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function __construct(int $caseType, bool $allowSpecialChars = true) |
48 | 48 | { |
49 | - if ($caseType > 4 || $caseType < 0) |
|
50 | - throw new InvalidRuleOption($caseType); |
|
49 | + if ($caseType > 4 || $caseType < 0) { |
|
50 | + throw new InvalidRuleOption($caseType); |
|
51 | + } |
|
51 | 52 | |
52 | 53 | $this->caseType = $caseType; |
53 | 54 | $this->strictCheck = !$allowSpecialChars; |
@@ -60,10 +61,11 @@ discard block |
||
60 | 61 | private function isMixed(string $text) : bool |
61 | 62 | { |
62 | 63 | if ($this->strictCheck) { |
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; |
|
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; |
|
68 | + } |
|
67 | 69 | } |
68 | 70 | |
69 | 71 | return preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
@@ -71,39 +73,43 @@ discard block |
||
71 | 73 | |
72 | 74 | private function isAllUpper(string $text) : bool |
73 | 75 | { |
74 | - if ($this->strictCheck) |
|
75 | - return ctype_upper($text); |
|
76 | - else |
|
77 | - return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
76 | + if ($this->strictCheck) { |
|
77 | + return ctype_upper($text); |
|
78 | + } else { |
|
79 | + return !preg_match('/[a-z]/', $text) && preg_match('/[A-Z]/', $text); |
|
80 | + } |
|
78 | 81 | |
79 | 82 | } |
80 | 83 | |
81 | 84 | private function isAllLower(string $text) : bool |
82 | 85 | { |
83 | - if ($this->strictCheck) |
|
84 | - return ctype_lower($text); |
|
85 | - else |
|
86 | - return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
86 | + if ($this->strictCheck) { |
|
87 | + return ctype_lower($text); |
|
88 | + } else { |
|
89 | + return preg_match('/[a-z]/', $text) && !preg_match('/[A-Z]/', $text); |
|
90 | + } |
|
87 | 91 | } |
88 | 92 | |
89 | 93 | private function isSomeLower(string $text) : bool |
90 | 94 | { |
91 | 95 | $containsLower = preg_match('/[a-z]/', $text); |
92 | 96 | |
93 | - if ($this->strictCheck) |
|
94 | - return !preg_match('/[\W]/', $text) && $containsLower; |
|
95 | - else |
|
96 | - return $containsLower; |
|
97 | + if ($this->strictCheck) { |
|
98 | + return !preg_match('/[\W]/', $text) && $containsLower; |
|
99 | + } else { |
|
100 | + return $containsLower; |
|
101 | + } |
|
97 | 102 | } |
98 | 103 | |
99 | 104 | private function isSomeUpper(string $text) : bool |
100 | 105 | { |
101 | 106 | $containsUpper = preg_match('/[A-Z]/', $text); |
102 | 107 | |
103 | - if ($this->strictCheck) |
|
104 | - return !preg_match('/[\W]/', $text) && $containsUpper; |
|
105 | - else |
|
106 | - return $containsUpper; |
|
108 | + if ($this->strictCheck) { |
|
109 | + return !preg_match('/[\W]/', $text) && $containsUpper; |
|
110 | + } else { |
|
111 | + return $containsUpper; |
|
112 | + } |
|
107 | 113 | } |
108 | 114 | |
109 | 115 | public function validate($data): Result |
@@ -128,10 +134,11 @@ discard block |
||
128 | 134 | break; |
129 | 135 | } |
130 | 136 | |
131 | - if ($isValid) |
|
132 | - return new Success(); |
|
133 | - else |
|
134 | - return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
137 | + if ($isValid) { |
|
138 | + return new Success(); |
|
139 | + } else { |
|
140 | + return new Failure(new RuleError(RuleErrorCode::CASING_MISMATCH, |
|
135 | 141 | "The given string doesn't match the required case")); |
142 | + } |
|
136 | 143 | } |
137 | 144 | } |
138 | 145 | \ No newline at end of file |