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

Ics   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 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