Completed
Push — master ( 9e79b8...d5f666 )
by Freek
16:43 queued 13:48
created

Ics::generate()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 1
1
<?php
2
3
namespace Spatie\CalendarLinks\Generators;
4
5
use Spatie\CalendarLinks\Link;
6
use Spatie\CalendarLinks\Generator;
7
8
class Ics implements Generator
9
{
10
    public function generate(Link $link): string
11
    {
12
        $url = 'data:text/calendar;charset=utf8,';
13
14
        $url .= 'BEGIN:VCALENDAR%0A';
15
        $url .= 'VERSION:2.0%0A';
16
        $url .= 'BEGIN:VEVENT%0A';
17
        $url .= 'DTSTART:'.$link->from->format('Ymd\THis').'%0A';
18
        $url .= 'DTEND:'.$link->to->format('Ymd\THis').'%0A';
19
        $url .= "SUMMARY:{$link->title}%0A";
20
21
        if ($link->description) {
22
            $url .= "DESCRIPTION:{$link->description}%0A";
23
        }
24
25
        if ($link->address) {
26
            $url .= 'LOCATION:'.str_replace(',', '', $link->address).'%0A';
27
        }
28
29
        $url .= 'END:VEVENT%0A';
30
        $url .= 'END:VCALENDAR';
31
32
        return $url;
33
    }
34
}
35