| Conditions | 7 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public static function filter($value, bool $allowNull = false) |
||
| 22 | { |
||
| 23 | if ($value === null && $allowNull) { |
||
| 24 | return null; |
||
| 25 | } |
||
| 26 | |||
| 27 | if ($value instanceof \DateTimeZone) { |
||
| 28 | return $value; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (!is_string($value) || trim($value) == '') { |
||
| 32 | throw new Exception('$value not a non-empty string'); |
||
| 33 | } |
||
| 34 | |||
| 35 | try { |
||
| 36 | return new \DateTimeZone($value); |
||
| 37 | } catch (\Exception $e) { |
||
| 38 | throw new Exception($e->getMessage(), $e->getCode(), $e); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 |