Google   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 22 4
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use Spatie\CalendarLinks\Generator;
6
use Spatie\CalendarLinks\Link;
7
8
/**
9
 * @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/google.md
10
 */
11
class Google implements Generator
12
{
13
    /** @var string {@see https://www.php.net/manual/en/function.date.php} */
14
    protected $dateFormat = 'Ymd';
15
    protected $dateTimeFormat = 'Ymd\THis';
16
17
    /** {@inheritdoc} */
18
    public function generate(Link $link): string
19
    {
20
        $url = 'https://calendar.google.com/calendar/render?action=TEMPLATE';
21
22
        $dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
23
        $url .= '&dates='.$link->from->format($dateTimeFormat).'/'.$link->to->format($dateTimeFormat);
24
        $url .= '&ctz='.$link->from->getTimezone()->getName();
25
26
        $url .= '&text='.urlencode($link->title);
27
28
        if ($link->description) {
29
            $url .= '&details='.urlencode($link->description);
30
        }
31
32
        if ($link->address) {
33
            $url .= '&location='.urlencode($link->address);
34
        }
35
36
        $url .= '&sprop=&sprop=name:';
37
38
        return $url;
39
    }
40
}
41