Skip to content

Commit 74a21e4

Browse files
fixing issues
1 parent 417e873 commit 74a21e4

File tree

11 files changed

+175
-90
lines changed

11 files changed

+175
-90
lines changed

src/Constants/ValidationRegex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class ValidationRegex
3737
/**
3838
* Separate strings by comma. (ana,gustav,john).
3939
*/
40-
public const SEPARATE_STRINGS_BY_COMMA = "/^[a-z]+(?:,[a-z]+)*$/";
40+
public const SEPARATE_STRINGS_BY_COMMA = "/^[a-zA-Z]+(?:,[a-zA-Z]+)*$/";
4141

4242
/**
4343
* Separate strings by underscore (ana_gustav_john).
4444
*/
45-
public const SEPARATE_STRINGS_BY_UNDERSCORE = "/^[a-z]+(?:_[a-z]+)*$/";
45+
public const SEPARATE_STRINGS_BY_UNDERSCORE = "/^[a-zA-Z]+(?:_[a-zA-Z]+)*$/";
4646
}

src/Enums/TestEnum.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Shergela\Validations\Enums;
4+
5+
enum TestEnum: string
6+
{
7+
case ONE = '1';
8+
case TWO = '2';
9+
case STRING_ONE = 'one';
10+
case STRING_TWO = 'two';
11+
}

src/Rules/SeparateIntegersByComma.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Contracts\Validation\ValidationRule;
7+
use Illuminate\Support\Str;
78
use Shergela\Validations\Constants\ValidationRegex as Regex;
89

910
class SeparateIntegersByComma implements ValidationRule
@@ -26,7 +27,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
2627
if (! preg_match(pattern: Regex::SEPARATE_INTEGERS_BY_COMMA, subject: $toString)) {
2728
$fail(
2829
$this->message == null
29-
? "Please separate (:attribute) integer values by comma. Entered value: {$toString}"
30+
? "Please separate (:attribute) integer values by comma. Entered value: `{$toString}`"
3031
: $this->message
3132
);
3233
}

src/Rules/SeparateStringsByComma.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Contracts\Validation\ValidationRule;
7+
use Illuminate\Support\Str;
78
use Shergela\Validations\Constants\ValidationRegex as Regex;
89

910
class SeparateStringsByComma implements ValidationRule
@@ -26,7 +27,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
2627
if (! preg_match(pattern: Regex::SEPARATE_STRINGS_BY_COMMA, subject: $toString)) {
2728
$fail(
2829
$this->message == null
29-
? "Please separate (:attribute) values by comma. Entered value: {$toString}"
30+
? "Please separate letter (:attribute) values by comma. Entered value: `{$toString}`"
3031
: $this->message
3132
);
3233
}

src/Rules/SeparateStringsByUnderscore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Contracts\Validation\ValidationRule;
7+
use Illuminate\Support\Str;
78
use Shergela\Validations\Constants\ValidationRegex as Regex;
89

910
class SeparateStringsByUnderscore implements ValidationRule
@@ -26,7 +27,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
2627
if (! preg_match(pattern: Regex::SEPARATE_STRINGS_BY_UNDERSCORE, subject: $toString)) {
2728
$fail(
2829
$this->message == null
29-
? "Please separate (:attribute) values by underscore. Entered value: {$toString}"
30+
? "Please separate (:attribute) values by underscore. Entered value: `{$toString}`"
3031
: $this->message
3132
);
3233
}

src/Rules/TimezoneRegionValidation.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
4343
if ($this->validateProvidedValues() === false) {
4444
$fail($this->customMessage == null ? $this->message : $this->customMessage);
4545
return;
46-
};
46+
}
4747

48-
if (! in_array($search, $this->getTimezoneLists())) {
48+
/**
49+
* Check if expected values match given values.
50+
*/
51+
if (! in_array($search, $this->cities)) {
4952
if ($this->customMessage !== null) {
5053
$fail($this->customMessage);
5154
} else {
52-
$fail(
53-
sprintf(
54-
"The city name [:attribute] (%s) is not in the valid timezone for (%s) list.",
55-
ucfirst($toString),
56-
ucfirst($this->timezoneGroup)
57-
)
58-
);
55+
$fail(sprintf("The city name [:attribute] (%s) is not selected correctly.", ucfirst($toString)));
5956
}
6057
}
6158
}
@@ -69,7 +66,7 @@ private function validateProvidedValues(): bool
6966
if (! in_array($city, $this->getTimezoneLists())) {
7067
$after = ucfirst(Str::after($city, '/'));
7168
$this->message = sprintf(
72-
"This timezone [%s] is not in the valid timezone for [%s].",
69+
"This timezone (:attribute) [%s] is not in the valid timezone for %s.",
7370
ucfirst($this->timezoneGroup . '/' . $after),
7471
ucfirst($this->timezoneGroup)
7572
);

src/Rules/TimezoneValidation.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Closure;
66
use Illuminate\Contracts\Validation\ValidationRule;
7-
use Illuminate\Support\Str;
87

98
class TimezoneValidation implements ValidationRule
109
{

src/Validation/BuildValidationRule.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Shergela\Validations\Rules\TimezoneValidation;
2020
use Shergela\Validations\Rules\UppercaseFirstLetter;
2121
use Shergela\Validations\Rules\UppercaseWord;
22-
use Shergela\Validations\Rules\UppercaseWords;
2322

2423
class BuildValidationRule
2524
{
@@ -42,7 +41,8 @@ class BuildValidationRule
4241
* @var string|null
4342
* Set custom message
4443
*/
45-
protected static ?string $validationMessage = null;
44+
protected ?string $validationMessage = null;
45+
protected ?string $timezoneValidationMessage = null;
4646

4747
/**
4848
* @var int|null
@@ -415,22 +415,22 @@ protected function buildValidationRules(): array
415415

416416
...(
417417
$this->uppercaseFirstLetter === true
418-
? [new UppercaseFirstLetter(message: static::$validationMessage)]
418+
? [new UppercaseFirstLetter(message: $this->validationMessage)]
419419
: []
420420
),
421421

422422
...(
423423
$this->lowercaseFirstLetter === true
424-
? [new LowercaseFirstLetter(message: static::$validationMessage)]
424+
? [new LowercaseFirstLetter(message: $this->validationMessage)]
425425
: []
426426
),
427427

428-
...($this->uppercaseWord === true ? [new UppercaseWord(message: static::$validationMessage)] : []),
429-
...($this->lowerCaseWord === true ? [new LowercaseWord(message: static::$validationMessage)] : []),
428+
...($this->uppercaseWord === true ? [new UppercaseWord(message: $this->validationMessage)] : []),
429+
...($this->lowerCaseWord === true ? [new LowercaseWord(message: $this->validationMessage)] : []),
430430

431431
...(
432432
$this->onlyLettersAndSpaces === true
433-
? [new OnlyLettersAndSpaces(message: static::$validationMessage)]
433+
? [new OnlyLettersAndSpaces(message: $this->validationMessage)]
434434
: []
435435
),
436436

@@ -447,7 +447,7 @@ protected function buildValidationRules(): array
447447

448448
...(
449449
$this->timezones !== null
450-
? [new TimezoneValidation(timezones: $this->timezones, message: static::$validationMessage)]
450+
? [new TimezoneValidation(timezones: $this->timezones, message: $this->timezoneValidationMessage)]
451451
: []
452452
),
453453

@@ -458,7 +458,7 @@ protected function buildValidationRules(): array
458458
cities: $this->timezoneIdentifierCities,
459459
timezoneGroupNumber: $this->dateTimezoneGroupNumber,
460460
timezoneGroup: $this->dateTimezoneGroupName,
461-
customMessage: static::$validationMessage,
461+
customMessage: $this->timezoneValidationMessage,
462462
)
463463
]
464464
: []
@@ -484,19 +484,19 @@ protected function buildValidationRules(): array
484484

485485
...(
486486
$this->separateIntegersByComma === true
487-
? [new IntegerByComma(message: static::$validationMessage)]
487+
? [new IntegerByComma(message: $this->validationMessage)]
488488
: []
489489
),
490490

491491
...(
492492
$this->separateStringsByComma === true
493-
? [new StringByComma(message: static::$validationMessage)]
493+
? [new StringByComma(message: $this->validationMessage)]
494494
: []
495495
),
496496

497497
...(
498498
$this->separateStringsByUnderscore === true
499-
? [new StringByUnderscore(message: static::$validationMessage)]
499+
? [new StringByUnderscore(message: $this->validationMessage)]
500500
: []
501501
),
502502

0 commit comments

Comments
 (0)