Completed
Push — master ( ec34b7...12a345 )
by Sebastian
01:04
created

Link::ics()   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
use Spatie\CalendarLinks\Generators\IcsGenerator;
9
use Spatie\CalendarLinks\Generators\YahooGenerator;
10
11
/**
12
 * @property string $title
13
 * @property \DateTime $from
14
 * @property \DateTime $to
15
 * @property string $description
16
 * @property string $address
17
 */
18
class Link
19
{
20
    /** @var string */
21
    protected $title;
22
23
    /** @var \DateTime */
24
    protected $from;
25
26
    /** @var \DateTime */
27
    protected $to;
28
29
    /** @var string */
30
    protected $description;
31
32
    /** @var string */
33
    protected $address;
34
35
    public function __construct(string $title, DateTime $from, DateTime $to)
36
    {
37
        $this->title = $title;
38
39
        if ($to < $from) {
40
            throw InvalidLink::invalidDateRange($from, $to);
41
        }
42
43
        $this->from = $from;
44
        $this->to = $to;
45
    }
46
47
    /**
48
     * @param string $title
49
     * @param \DateTime $from
50
     * @param \DateTime $to
51
     *
52
     * @return static
53
     */
54
    public static function create(string $title, DateTime $from, DateTime $to)
55
    {
56
        return new static($title, $from, $to);
57
    }
58
59
    /**
60
     * @param string $description
61
     *
62
     * @return $this
63
     */
64
    public function description(string $description)
65
    {
66
        $this->description = $description;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param string $address
73
     *
74
     * @return $this
75
     */
76
    public function address(string $address)
77
    {
78
        $this->address = $address;
79
80
        return $this;
81
    }
82
83
    public function google(): string
84
    {
85
        return (new GoogleGenerator())->generate($this);
86
    }
87
88
    public function ics(): string
89
    {
90
        return (new IcsGenerator())->generate($this);
91
    }
92
93
    public function yahoo(): string
94
    {
95
        return (new YahooGenerator())->generate($this);
96
    }
97
98
    public function __get($property)
99
    {
100
        return $this->$property;
101
    }
102
}
103