1 | <?php |
||
21 | class Link |
||
22 | { |
||
23 | /** @var string */ |
||
24 | protected $title; |
||
25 | |||
26 | /** @var \DateTime */ |
||
27 | protected $from; |
||
28 | |||
29 | /** @var \DateTime */ |
||
30 | protected $to; |
||
31 | |||
32 | /** @var string */ |
||
33 | protected $description; |
||
34 | |||
35 | /** @var bool */ |
||
36 | protected $allDay; |
||
37 | |||
38 | /** @var string */ |
||
39 | protected $address; |
||
40 | |||
41 | public function __construct(string $title, DateTimeInterface $from, DateTimeInterface $to, bool $allDay = false) |
||
42 | { |
||
43 | $this->title = $title; |
||
44 | $this->allDay = $allDay; |
||
45 | |||
46 | if ($to < $from) { |
||
47 | throw InvalidLink::invalidDateRange($from, $to); |
||
48 | } |
||
49 | |||
50 | $this->from = clone $from; |
||
|
|||
51 | $this->to = clone $to; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param string $title |
||
56 | * @param \DateTimeInterface $from |
||
57 | * @param \DateTimeInterface $to |
||
58 | * @param bool $allDay |
||
59 | * |
||
60 | * @return static |
||
61 | * @throws InvalidLink |
||
62 | */ |
||
63 | public static function create(string $title, DateTimeInterface $from, DateTimeInterface $to, bool $allDay = false) |
||
64 | { |
||
65 | return new static($title, $from, $to, $allDay); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param string $title |
||
70 | * @param DateTimeInterface $fromDate |
||
71 | * @param int $numberOfDays |
||
72 | * |
||
73 | * @return Link |
||
74 | * @throws InvalidLink |
||
75 | */ |
||
76 | public static function createAllDay(string $title, DateTimeInterface $fromDate, int $numberOfDays = 1): self |
||
77 | { |
||
78 | $from = (clone $fromDate)->modify('midnight'); |
||
79 | $to = (clone $from)->modify("+$numberOfDays days"); |
||
80 | |||
81 | return new self($title, $from, $to, true); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $description |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function description(string $description) |
||
90 | { |
||
91 | $this->description = $description; |
||
92 | |||
93 | return $this; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @param string $address |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function address(string $address) |
||
107 | |||
108 | public function formatWith(Generator $generator): string |
||
109 | { |
||
110 | return $generator->generate($this); |
||
111 | } |
||
112 | |||
113 | public function google(): string |
||
117 | |||
118 | public function ics(array $options = []): string |
||
122 | |||
123 | public function yahoo(): string |
||
127 | |||
128 | public function webOutlook(): string |
||
132 | |||
133 | public function office365(): string |
||
137 | |||
138 | public function __get($property) |
||
142 | } |
||
143 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.