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