GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b4985c...2d21f4 )
by Ruben
03:45
created

Calendar::getRequiredProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\IcalendarGenerator\Components;
4
5
use Closure;
6
use Spatie\IcalendarGenerator\ComponentPayload;
7
use Spatie\IcalendarGenerator\PropertyTypes\DurationPropertyType;
8
9
final class Calendar extends Component
10
{
11
    /** @var array */
12
    private $events = [];
13
14
    /** @var string|null */
15
    private $name;
16
17
    /** @var string|null */
18
    private $description;
19
20
    /** @var bool */
21
    private $withTimezone = false;
22
23
    /** @var int|null */
24
    private $refreshInterval;
25
26
    public static function create(string $name = null): Calendar
27
    {
28
        return new self($name);
29
    }
30
31
    public function __construct(string $name = null)
32
    {
33
        $this->name = $name;
34
    }
35
36
    public function getComponentType(): string
37
    {
38
        return 'CALENDAR';
39
    }
40
41
    public function getRequiredProperties(): array
42
    {
43
        return [
44
            'VERSION',
45
            'PRODID',
46
        ];
47
    }
48
49
    public function name(string $name): Calendar
50
    {
51
        $this->name = $name;
52
53
        return $this;
54
    }
55
56
    public function description(string $description): Calendar
57
    {
58
        $this->description = $description;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @param $event \Spatie\IcalendarGenerator\Components\Event|array|Closure
65
     *
66
     * @return \Spatie\IcalendarGenerator\Components\Calendar
67
     */
68
    public function event($event): Calendar
69
    {
70
        if (is_null($event)) {
71
            return $this;
72
        }
73
74
        $events = is_array($event) ? $event : [$event];
75
76
        $this->events = array_map(function ($eventToResolve) {
77
            if (! is_callable($eventToResolve)) {
78
                return $eventToResolve;
79
            }
80
81
            $newEvent = new Event();
82
83
            $eventToResolve($newEvent);
84
85
            return $newEvent;
86
        }, $events);
87
88
        return $this;
89
    }
90
91
    public function withTimezone(): Calendar
92
    {
93
        $this->withTimezone = true;
94
95
        return $this;
96
    }
97
98
    public function refreshInterval(int $minutes): Calendar
99
    {
100
        $this->refreshInterval = $minutes;
101
102
        return $this;
103
    }
104
105
    public function get(): string
106
    {
107
        return $this->toString();
108
    }
109
110
    public function getPayload(): ComponentPayload
111
    {
112
        $events = $this->events;
113
114
        if ($this->withTimezone) {
115
            array_walk($events, function (Event $event) {
116
                $event->withTimezone();
117
            });
118
        }
119
120
        return ComponentPayload::create($this->getComponentType())
121
            ->textProperty('VERSION', '2.0')
122
            ->textProperty('PRODID', 'spatie/icalendar-generator')
123
            ->textProperty('NAME', $this->name)
124
            ->alias('NAME', ['X-WR-CALNAME'])
125
            ->textProperty('DESCRIPTION', $this->description)
126
            ->when(! is_null($this->refreshInterval), function (ComponentPayload $payload) {
127
                $payload->property(new DurationPropertyType('REFRESH-INTERVAL', $this->refreshInterval));
128
            })
129
            ->subComponent(...$events);
130
    }
131
}
132