Completed
Pull Request — master (#67)
by
unknown
01:17
created

Link::yahoo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CalendarLinks;
4
5
use DateTime;
6
use Spatie\CalendarLinks\Generators\Ics;
7
use Spatie\CalendarLinks\Generators\Yahoo;
8
use Spatie\CalendarLinks\Generators\Google;
9
use Spatie\CalendarLinks\Generators\WebOutlook;
10
use Spatie\CalendarLinks\Exceptions\InvalidLink;
11
12
/**
13
 * @property-read string $title
14
 * @property-read \DateTime $from
15
 * @property-read \DateTime $to
16
 * @property-read string $description
17
 * @property-read string $address
18
 * @property-read bool $allDay
19
 */
20
class Link
21
{
22
    /** @var string */
23
    protected $title;
24
25
    /** @var \DateTime */
26
    protected $from;
27
28
    /** @var \DateTime */
29
    protected $to;
30
31
    /** @var string */
32
    protected $description;
33
34
    /** @var bool */
35
    protected $allDay;
36
37
    /** @var string */
38
    protected $address;
39
40
    /** @var string */
41
    protected $attendee;
42
43
    public function __construct(string $title, DateTime $from, DateTime $to, bool $allDay = false)
44
    {
45
        $this->title = $title;
46
        $this->allDay = $allDay;
47
48
        if ($to < $from) {
49
            throw InvalidLink::invalidDateRange($from, $to);
50
        }
51
52
        $this->from = clone $from;
53
        $this->to = clone $to;
54
55
        if ($this->allDay) {
56
            $this->from = clone $from;
57
            $this->to = clone $from;
58
        }
59
    }
60
61
    /**
62
     * @param string $title
63
     * @param \DateTime $from
64
     * @param \DateTime $to
65
     * @param bool $allDay
66
     *
67
     * @return static
68
     * @throws InvalidLink
69
     */
70
    public static function create(string $title, DateTime $from, DateTime $to, bool $allDay = false)
71
    {
72
        return new static($title, $from, $to, $allDay);
73
    }
74
75
    /**
76
     * @param string $description
77
     *
78
     * @return $this
79
     */
80
    public function description(string $description)
81
    {
82
        $this->description = $description;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @param string $address
89
     *
90
     * @return $this
91
     */
92
    public function address(string $address)
93
    {
94
        $this->address = $address;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @param string $attendee
101
     *
102
     * @return $this
103
     */
104
    public function attendee(string $attendee)
105
    {
106
        $this->attendee = $attendee;
107
        return $this;
108
    }
109
110
    public function google(): string
111
    {
112
        return (new Google())->generate($this);
113
    }
114
115
    public function ics(): string
116
    {
117
        return (new Ics())->generate($this);
118
    }
119
120
    public function yahoo(): string
121
    {
122
        return (new Yahoo())->generate($this);
123
    }
124
125
    public function webOutlook(): string
126
    {
127
        return (new WebOutlook())->generate($this);
128
    }
129
130
    public function __get($property)
131
    {
132
        return $this->$property;
133
    }
134
}
135