Completed
Pull Request — master (#57)
by
unknown
01:14
created

Link::__get()   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 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
 * @property-read array $attendees
20
 */
21
class Link
22
{
23
    /** @var string */
24
    protected $title;
25
26
    /** @var \DateTime */
27
    protected $from;
28
29
    /** @var \DateTime */
30
    protected $to;
31
32
    /** @var string */
33
    protected $description;
34
35
    /** @var bool */
36
    protected $allDay;
37
38
    /** @var string */
39
    protected $address;
40
41
    /** @var array */
42
    protected $attendees;
43
44
    public function __construct(string $title, DateTime $from, DateTime $to, bool $allDay = false)
45
    {
46
        $this->title = $title;
47
        $this->allDay = $allDay;
48
49
        if ($to < $from) {
50
            throw InvalidLink::invalidDateRange($from, $to);
51
        }
52
53
        $this->from = clone $from;
54
        $this->to = clone $to;
55
56
        if ($this->allDay) {
57
            $this->from = clone $from;
58
            $this->to = clone $from;
59
        }
60
    }
61
62
    /**
63
     * @param string $title
64
     * @param \DateTime $from
65
     * @param \DateTime $to
66
     * @param bool $allDay
67
     *
68
     * @return static
69
     * @throws InvalidLink
70
     */
71
    public static function create(string $title, DateTime $from, DateTime $to, bool $allDay = false)
72
    {
73
        return new static($title, $from, $to, $allDay);
74
    }
75
76
    /**
77
     * @param string $description
78
     *
79
     * @return $this
80
     */
81
    public function description(string $description)
82
    {
83
        $this->description = $description;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @param string $address
90
     *
91
     * @return $this
92
     */
93
    public function address(string $address)
94
    {
95
        $this->address = $address;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @param array $emails
0 ignored issues
show
Bug introduced by
There is no parameter named $emails. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
102
     *
103
     * @return $this
104
     */
105
    public function attendees(string $attendees)
106
    {
107
        if (! is_array($attendees)) {
108
            $attendees = explode(',', $attendees);
109
        }
110
111
        $this->attendees = $attendees;
112
113
        return $this;
114
    }
115
116
    public function google(): string
117
    {
118
        return (new Google())->generate($this);
119
    }
120
121
    public function ics(): string
122
    {
123
        return (new Ics())->generate($this);
124
    }
125
126
    public function yahoo(): string
127
    {
128
        return (new Yahoo())->generate($this);
129
    }
130
131
    public function webOutlook(): string
132
    {
133
        return (new WebOutlook())->generate($this);
134
    }
135
136
    public function __get($property)
137
    {
138
        return $this->$property;
139
    }
140
}
141