Skip to content

Commit 021da40

Browse files
committed
Update formatting of password rule, fix title case test
1 parent 70420e2 commit 021da40

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/Rules/StrongPassword.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace F9Web\ValidationRules\Rules;
66

77
use F9Web\ValidationRules\Rule;
8+
89
use function __;
910
use function mb_strlen;
1011
use function preg_match_all;
@@ -38,24 +39,31 @@ public function passes($attribute, $value): bool
3839
{
3940
$this->setAttribute($attribute);
4041

41-
$containsUppercase = '/[A-Z]/';
42-
$containsLowercase = '/[a-z]/';
43-
$specialCharacters = '/['.$this->specialCharacters.']/';
44-
$numbers = '/[0-9]/';
45-
46-
if ($this->mustIncludeUppercaseCharacters && preg_match_all($containsUppercase, $value, $o) === 0) {
42+
if (
43+
$this->mustIncludeUppercaseCharacters &&
44+
preg_match_all('/[A-Z]/', $value, $o) === 0
45+
) {
4746
return false;
4847
}
4948

50-
if ($this->mustIncludeLowercaseCharacters && preg_match_all($containsLowercase, $value, $o) === 0) {
49+
if (
50+
$this->mustIncludeLowercaseCharacters &&
51+
preg_match_all('/[a-z]/', $value, $o) === 0
52+
) {
5153
return false;
5254
}
5355

54-
if ($this->mustIncludeSpecialCharacters && preg_match_all($specialCharacters, $value, $o) === 0) {
56+
if (
57+
$this->mustIncludeSpecialCharacters &&
58+
preg_match_all('/['.$this->specialCharacters.']/', $value, $o) === 0
59+
) {
5560
return false;
5661
}
5762

58-
if ($this->mustIncludeNumbers && preg_match_all($numbers, $value, $o) === 0) {
63+
if (
64+
$this->mustIncludeNumbers &&
65+
preg_match_all('/[0-9]/', $value, $o) === 0
66+
) {
5967
return false;
6068
}
6169

@@ -153,6 +161,8 @@ public function message(): string
153161
{
154162
$key = 'f9web-validation-rules::messages.'.$this->getMessageKey();
155163

164+
$message = [];
165+
156166
$message[] = __(
157167
$key.'.base',
158168
[

tests/Rules/TitleCaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function it_passes_relevant_data_to_the_validation_message()
4545
public function sampleDataProvider(): array
4646
{
4747
return [
48-
['It’s Not A Bug. It’s A Feature!', true],
49-
['It’s not a bug. It’s a feature!', false],
48+
['Not A Bug, Ok?', true],
49+
['not a bug, OK?', false],
5050
['Éasy money', false],
5151
['Éasy Money', true],
5252
['A', true],

0 commit comments

Comments
 (0)