1 | <?php |
||
9 | class Date implements ValueObjectInterface |
||
10 | { |
||
11 | /** @var Year */ |
||
12 | protected $year; |
||
13 | |||
14 | /** @var Month */ |
||
15 | protected $month; |
||
16 | |||
17 | /** @var MonthDay */ |
||
18 | protected $day; |
||
19 | |||
20 | /** |
||
21 | * Returns a new Date from native year, month and day values |
||
22 | * |
||
23 | * @param int $year |
||
|
|||
24 | * @param string $month |
||
25 | * @param int $day |
||
26 | * @return Date |
||
27 | */ |
||
28 | 3 | public static function fromNative() |
|
29 | { |
||
30 | 3 | $args = func_get_args(); |
|
31 | |||
32 | 3 | $year = new Year($args[0]); |
|
33 | 3 | $month = Month::fromNative($args[1]); |
|
34 | 3 | $day = new MonthDay($args[2]); |
|
35 | |||
36 | 3 | return new static($year, $month, $day); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns a new Date from a native PHP \DateTime |
||
41 | * |
||
42 | * @param \DateTime $date |
||
43 | * @return Date |
||
44 | */ |
||
45 | 3 | public static function fromNativeDateTime(\DateTime $date) |
|
46 | { |
||
47 | 3 | $year = \intval($date->format('Y')); |
|
48 | 3 | $month = Month::fromNativeDateTime($date); |
|
49 | 3 | $day = \intval($date->format('d')); |
|
50 | |||
51 | 3 | return new static(new Year($year), $month, new MonthDay($day)); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns current Date |
||
56 | * |
||
57 | * @return Date |
||
58 | */ |
||
59 | 3 | public static function now() |
|
60 | { |
||
61 | 3 | $date = new static(Year::now(), Month::now(), MonthDay::now()); |
|
62 | |||
63 | 3 | return $date; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Create a new Date |
||
68 | * |
||
69 | * @param Year $year |
||
70 | * @param Month $month |
||
71 | * @param MonthDay $day |
||
72 | * @throws InvalidDateException |
||
73 | */ |
||
74 | 28 | public function __construct(Year $year, Month $month, MonthDay $day) |
|
75 | { |
||
76 | 28 | \DateTime::createFromFormat('Y-F-j', \sprintf('%d-%s-%d', $year->toNative(), $month, $day->toNative())); |
|
77 | 28 | $nativeDateErrors = \DateTime::getLastErrors(); |
|
78 | |||
79 | 28 | if ($nativeDateErrors['warning_count'] > 0 || $nativeDateErrors['error_count'] > 0) { |
|
80 | 1 | throw new InvalidDateException($year->toNative(), $month->toNative(), $day->toNative()); |
|
81 | } |
||
82 | |||
83 | 27 | $this->year = $year; |
|
84 | 27 | $this->month = $month; |
|
85 | 27 | $this->day = $day; |
|
86 | 27 | } |
|
87 | |||
88 | /** |
||
89 | * Tells whether two Date are equal by comparing their values |
||
90 | * |
||
91 | * @param ValueObjectInterface $date |
||
92 | * @return bool |
||
93 | */ |
||
94 | 12 | public function sameValueAs(ValueObjectInterface $date) |
|
104 | |||
105 | /** |
||
106 | * Get year |
||
107 | * |
||
108 | * @return Year |
||
109 | */ |
||
110 | 22 | public function getYear() |
|
114 | |||
115 | /** |
||
116 | * Get month |
||
117 | * |
||
118 | * @return Month |
||
119 | */ |
||
120 | 22 | public function getMonth() |
|
124 | |||
125 | /** |
||
126 | * Get day |
||
127 | * |
||
128 | * @return MonthDay |
||
129 | */ |
||
130 | 22 | public function getDay() |
|
134 | |||
135 | /** |
||
136 | * Returns a native PHP \DateTime version of the current Date |
||
137 | * |
||
138 | * @return \DateTime |
||
139 | */ |
||
140 | 7 | public function toNativeDateTime() |
|
152 | |||
153 | function jsonSerialize() |
||
157 | |||
158 | /** |
||
159 | * Returns date as string in format Y-n-j |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | 6 | public function __toString() |
|
167 | } |
||
168 |
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.