Completed
Push — master ( 6f3d75...f2858a )
by
unknown
12s
created

WebOutlook   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 24 4
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use DateTimeZone;
6
use Spatie\CalendarLinks\Link;
7
use Spatie\CalendarLinks\Generator;
8
9
/**
10
 * @see https://answers.microsoft.com/en-us/outlook_com/forum/ocalendar-oaddevent/link-to-outlook-live-calendar-correct-url/67b96c7d-336a-4ae9-b0fe-3b35ed8e959a
11
 */
12
class WebOutlook implements Generator
13
{
14
    /** {@inheritdoc} */
15
    public function generate(Link $link): string
16
    {
17
        $url = 'https://outlook.live.com/owa/?path=/calendar/action/compose&rru=addevent';
18
19
        $utcStartDateTime = (clone $link->from)->setTimezone(new DateTimeZone('UTC'));
20
        $utcEndDateTime = (clone $link->to)->setTimezone(new DateTimeZone('UTC'));
21
        $url .= '&startdt='.$utcStartDateTime->format('Ymd\THis');
22
        $url .= '&enddt='.$utcEndDateTime->format('Ymd\THis');
23
        if ($link->allDay) {
24
            $url .= '&allday=true';
25
        }
26
27
        $url .= '&subject='.urlencode($link->title);
28
29
        if ($link->description) {
30
            $url .= '&body='.urlencode($link->description);
31
        }
32
33
        if ($link->address) {
34
            $url .= '&location='.urlencode($link->address);
35
        }
36
37
        return $url;
38
    }
39
}
40