| Total Complexity | 6 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 18 | trait TimezoneValidationTrait |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Validates that the given node represents a valid PHP timezone. |
||
| 22 | * |
||
| 23 | * @throws InvalidTimezoneException If the timezone is invalid |
||
| 24 | */ |
||
| 25 | 18 | protected function validateTimezone(Node $node, string $functionName): void |
|
| 26 | { |
||
| 27 | 18 | if (!$node instanceof Literal || !\is_string($node->value)) { |
|
| 28 | 3 | throw InvalidTimezoneException::forNonLiteralNode($node::class, $functionName); |
|
| 29 | } |
||
| 30 | |||
| 31 | 15 | $timezone = \trim((string) $node->value, "'\""); |
|
| 32 | |||
| 33 | 15 | if (!$this->isValidTimezone($timezone)) { |
|
| 34 | 12 | throw InvalidTimezoneException::forInvalidTimezone($timezone, $functionName); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 15 | private function isValidTimezone(string $timezone): bool |
|
| 46 | } |
||
| 47 | } |
||
| 49 |