WebOutlook   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 28 5
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use DateTimeZone;
6
use Spatie\CalendarLinks\Generator;
7
use Spatie\CalendarLinks\Link;
8
9
/**
10
 * @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/outlook-live.md
11
 */
12
class WebOutlook implements Generator
13
{
14
    protected const BASE_URL = 'https://outlook.live.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent';
15
16
    /** @var string {@see https://www.php.net/manual/en/function.date.php} */
17
    protected $dateFormat = 'Y-m-d';
18
    protected $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
19
20
    /** {@inheritdoc} */
21
    public function generate(Link $link): string
22
    {
23
        $url = static::BASE_URL;
24
25
        $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
26
27
        $utcStartDateTime = (clone $link->from)->setTimezone(new DateTimeZone('UTC'));
28
        $utcEndDateTime = (clone $link->to)->setTimezone(new DateTimeZone('UTC'));
29
30
        $url .= '&startdt='.$utcStartDateTime->format($dateTimeFormat);
31
        $url .= '&enddt='.$utcEndDateTime->format($dateTimeFormat);
32
33
        if ($link->allDay) {
34
            $url .= '&allday=true';
35
        }
36
37
        $url .= '&subject='.urlencode($link->title);
38
39
        if ($link->description) {
40
            $url .= '&body='.urlencode($link->description);
41
        }
42
43
        if ($link->address) {
44
            $url .= '&location='.urlencode($link->address);
45
        }
46
47
        return $url;
48
    }
49
}
50