1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ValueObjects\DateTime; |
4
|
|
|
|
5
|
|
|
use ValueObjects\DateTime\Exception\InvalidTimeZoneException; |
6
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
7
|
|
|
use ValueObjects\Util\Util; |
8
|
|
|
use ValueObjects\ValueObjectInterface; |
9
|
|
|
|
10
|
|
|
class TimeZone implements ValueObjectInterface |
11
|
|
|
{ |
12
|
|
|
/** @var StringLiteral */ |
13
|
|
|
protected $name; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Returns a new Time object from native timezone name |
17
|
|
|
* |
18
|
|
|
* @param string $name |
|
|
|
|
19
|
|
|
* @return self |
20
|
|
|
*/ |
21
|
4 |
|
public static function fromNative() |
22
|
|
|
{ |
23
|
4 |
|
$args = func_get_args(); |
24
|
|
|
|
25
|
4 |
|
$name = new StringLiteral($args[0]); |
26
|
|
|
|
27
|
4 |
|
return new static($name); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns a new Time from a native PHP \DateTime |
32
|
|
|
* |
33
|
|
|
* @param \DateTimeZone $timezone |
34
|
|
|
* @return self |
35
|
|
|
*/ |
36
|
2 |
|
public static function fromNativeDateTimeZone(\DateTimeZone $timezone) |
37
|
|
|
{ |
38
|
2 |
|
return static::fromNative($timezone->getName()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns default TimeZone |
43
|
|
|
* |
44
|
|
|
* @return self |
45
|
|
|
*/ |
46
|
2 |
|
public static function fromDefault() |
47
|
|
|
{ |
48
|
2 |
|
return new static(new StringLiteral(date_default_timezone_get())); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns a new TimeZone object |
53
|
|
|
* |
54
|
|
|
* @param StringLiteral $name |
55
|
|
|
* @throws InvalidTimeZoneException |
56
|
|
|
*/ |
57
|
17 |
|
public function __construct(StringLiteral $name) |
58
|
|
|
{ |
59
|
17 |
|
if (!in_array($name->toNative(), timezone_identifiers_list())) { |
60
|
1 |
|
throw new InvalidTimeZoneException($name); |
61
|
|
|
} |
62
|
|
|
|
63
|
16 |
|
$this->name = $name; |
64
|
16 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns a native PHP \DateTimeZone version of the current TimeZone. |
68
|
|
|
* |
69
|
|
|
* @return \DateTimeZone |
70
|
|
|
*/ |
71
|
3 |
|
public function toNativeDateTimeZone() |
72
|
|
|
{ |
73
|
3 |
|
return new \DateTimeZone($this->getName()->toNative()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Tells whether two DateTimeZone are equal by comparing their names |
78
|
|
|
* |
79
|
|
|
* @param ValueObjectInterface $timezone |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
7 |
|
public function sameValueAs(ValueObjectInterface $timezone) |
83
|
|
|
{ |
84
|
7 |
|
if (false === Util::classEquals($this, $timezone)) { |
85
|
1 |
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
7 |
|
return $this->getName()->sameValueAs($timezone->getName()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns timezone name |
93
|
|
|
* |
94
|
|
|
* @return StringLiteral |
95
|
|
|
*/ |
96
|
15 |
|
public function getName() |
97
|
|
|
{ |
98
|
15 |
|
return clone $this->name; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns timezone name as string |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
4 |
|
public function __toString() |
107
|
|
|
{ |
108
|
4 |
|
return $this->getName()->__toString(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.