Completed
Push — master ( 6f3d75...f2858a )
by
unknown
12s
created

Link::webOutlook()   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 string $title
14
 * @property \DateTime $from
15
 * @property \DateTime $to
16
 * @property string $description
17
 * @property string $address
18
 * @property 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
    public function __construct(string $title, DateTime $from, DateTime $to, bool $allDay = false)
41
    {
42
        $this->title = $title;
43
        $this->allDay = $allDay;
44
45
        if ($to < $from) {
46
            throw InvalidLink::invalidDateRange($from, $to);
47
        }
48
49
        $this->from = clone $from;
50
        $this->to = clone $to;
51
52
        if ($this->allDay) {
53
            $this->from = clone $from;
54
            $this->to = clone $from;
55
        }
56
    }
57
58
    /**
59
     * @param string $title
60
     * @param \DateTime $from
61
     * @param \DateTime $to
62
     * @param bool $allDay
63
     *
64
     * @return static
65
     * @throws InvalidLink
66
     */
67
    public static function create(string $title, DateTime $from, DateTime $to, bool $allDay = false)
68
    {
69
        return new static($title, $from, $to, $allDay);
70
    }
71
72
    /**
73
     * @param string $description
74
     *
75
     * @return $this
76
     */
77
    public function description(string $description)
78
    {
79
        $this->description = $description;
80
81
        return $this;
82
    }
83
84
    /**
85
     * @param string $address
86
     *
87
     * @return $this
88
     */
89
    public function address(string $address)
90
    {
91
        $this->address = $address;
92
93
        return $this;
94
    }
95
96
    public function google(): string
97
    {
98
        return (new Google())->generate($this);
99
    }
100
101
    public function ics(): string
102
    {
103
        return (new Ics())->generate($this);
104
    }
105
106
    public function yahoo(): string
107
    {
108
        return (new Yahoo())->generate($this);
109
    }
110
111
    public function webOutlook(): string
112
    {
113
        return (new WebOutlook())->generate($this);
114
    }
115
116
    public function __get($property)
117
    {
118
        return $this->$property;
119
    }
120
}
121