Completed
Pull Request — master (#95)
by
unknown
01:04
created

Office365::generate()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 28

Duplication

Lines 28
Ratio 100 %

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 9.1608
c 0
b 0
f 0
cc 5
nc 16
nop 1
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use DateTimeZone;
6
use Spatie\CalendarLinks\Generator;
7
use Spatie\CalendarLinks\Link;
8
9 View Code Duplication
class Office365 implements Generator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /** @var string {@see https://www.php.net/manual/en/function.date.php} */
12
    protected $dateFormat = 'Y-m-d';
13
    protected $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
14
15
    /** {@inheritdoc} */
16
    public function generate(Link $link): string
17
    {
18
        $url = 'https://outlook.office.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent';
19
20
        $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
21
22
        $utcStartDateTime = (clone $link->from)->setTimezone(new DateTimeZone('UTC'));
23
        $utcEndDateTime = (clone $link->to)->setTimezone(new DateTimeZone('UTC'));
24
25
        $url .= '&startdt='.$utcStartDateTime->format($dateTimeFormat);
26
        $url .= '&enddt='.$utcEndDateTime->format($dateTimeFormat);
27
28
        if ($link->allDay) {
29
            $url .= '&allday=true';
30
        }
31
32
        $url .= '&subject='.urlencode($link->title);
33
34
        if ($link->description) {
35
            $url .= '&body='.urlencode($link->description);
36
        }
37
38
        if ($link->address) {
39
            $url .= '&location='.urlencode($link->address);
40
        }
41
42
        return $url;
43
    }
44
}
45