Completed
Push — master ( 7f69a4...136497 )
by Freek
02:44 queued 01:43
created

Link::ical()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CalendarLinks;
4
5
use DateTime;
6
use Spatie\CalendarLinks\Exceptions\InvalidLink;
7
use Spatie\CalendarLinks\Generators\GoogleGenerator;
8
9
/**
10
 * @property string $title
11
 * @property \DateTime $from
12
 * @property \DateTime $to
13
 * @property string $description
14
 * @property string $address
15
 */
16
class Link
17
{
18
    /** @var string */
19
    protected $title;
20
21
    /** @var \DateTime */
22
    protected $from;
23
24
    /** @var \DateTime */
25
    protected $to;
26
27
    /** @var string */
28
    protected $description;
29
30
    /** @var string */
31
    protected $address;
32
33
    public function __construct(string $title, DateTime $from, DateTime $to)
34
    {
35
        $this->title = $title;
36
37
        if ($to < $from) {
38
            throw InvalidLink::invalidDateRange($from, $to);
39
        }
40
41
        $this->from = $from;
42
        $this->to = $to;
43
    }
44
45
    /**
46
     * @param string $title
47
     * @param \DateTime $from
48
     * @param \DateTime $to
49
     *
50
     * @return static
51
     */
52
    public static function create(string $title, DateTime $from, DateTime $to)
53
    {
54
        return new static($title, $from, $to);
55
    }
56
57
    /**
58
     * @param string $description
59
     *
60
     * @return $this
61
     */
62
    public function description(string $description)
63
    {
64
        $this->description = $description;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @param string $address
71
     *
72
     * @return $this
73
     */
74
    public function address(string $address)
75
    {
76
        $this->address = $address;
77
78
        return $this;
79
    }
80
81
    public function google(): string
82
    {
83
        return (new GoogleGenerator())->generate($this);
84
    }
85
86
    public function __get($property)
87
    {
88
        return $this->$property;
89
    }
90
}
91