Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit c15838c

Browse files
committed
chore: refactored timezone unexpected error handling
1 parent 35b66c4 commit c15838c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Rule/Timezone.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ public function __construct(
1717

1818
public function assert(mixed $value, string $name): void
1919
{
20-
if ($this->countryCode !== null) {
20+
if ($this->timezoneGroup === \DateTimeZone::PER_COUNTRY) {
21+
// Country code is required when using PER_COUNTRY timezone group
22+
if ($this->countryCode === null) {
23+
throw new UnexpectedValueException(
24+
'A country code is required when timezone group is \DateTimeZone::PER_COUNTRY.'
25+
);
26+
}
27+
2128
// Normalize country code
2229
$this->countryCode = strtoupper($this->countryCode);
2330

@@ -29,12 +36,6 @@ public function assert(mixed $value, string $name): void
2936
}
3037
}
3138

32-
if ($this->timezoneGroup === \DateTimeZone::PER_COUNTRY && $this->countryCode === null) {
33-
throw new UnexpectedValueException(
34-
'A country code must be given when timezone group is \DateTimeZone::PER_COUNTRY.'
35-
);
36-
}
37-
3839
if (!\in_array($value, \DateTimeZone::listIdentifiers($this->timezoneGroup, $this->countryCode), true)) {
3940
throw new TimezoneException(
4041
message: $this->message,

0 commit comments

Comments
 (0)