Completed
Pull Request — master (#51)
by
unknown
01:13
created

Link::eventUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
    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 $eventUrl
86
     *
87
     * @return $this
88
     */
89
    public function eventUrl(string $eventUrl)
90
    {
91
        $this->eventUrl = $eventUrl;
0 ignored issues
show
Bug introduced by
The property eventUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
92
93
        return $this;
94
    }
95
96
    /**
97
     * @param string $address
98
     *
99
     * @return $this
100
     */
101
    public function address(string $address)
102
    {
103
        $this->address = $address;
104
105
        return $this;
106
    }
107
108
    public function google(): string
109
    {
110
        return (new Google())->generate($this);
111
    }
112
113
    public function ics(): string
114
    {
115
        return (new Ics())->generate($this);
116
    }
117
118
    public function yahoo(): string
119
    {
120
        return (new Yahoo())->generate($this);
121
    }
122
123
    public function webOutlook(): string
124
    {
125
        return (new WebOutlook())->generate($this);
126
    }
127
128
    public function __get($property)
129
    {
130
        return $this->$property;
131
    }
132
}
133