Completed
Push — master ( ec34b7...12a345 )
by Sebastian
01:04
created

IcsGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B generate() 0 24 3
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use Spatie\CalendarLinks\Link;
6
use Spatie\CalendarLinks\Generator;
7
8
class IcsGenerator implements Generator
9
{
10
    public function generate(Link $link): string
11
    {
12
        $url = 'data:text/calendar;charset=utf8,';
13
14
        $url .= "BEGIN:VCALENDAR\n";
15
        $url .= "VERSION:2.0\n";
16
        $url .= "BEGIN:VEVENT\n";
17
        $url .= "DTSTART:".$link->from->format('Ymd\THis')."\n";
18
        $url .= "DTEND:".$link->to->format('Ymd\THis')."\n";
19
        $url .= "SUMMARY:{$link->title}\n";
20
21
        if ($link->description) {
22
            $url .= "DESCRIPTION:{$link->description}\n";
23
        }
24
25
        if ($link->address) {
26
            $url .= "LOCATION:".str_replace(',', '', $link->address)."\n";
27
        }
28
29
        $url .= "END:VEVENT\n";
30
        $url .= "END:VCALENDAR";
31
32
        return $url;
33
    }
34
}
35