Completed
Push — master ( 031a53...ec34b7 )
by Sebastian
01:28
created

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