Completed
Pull Request — master (#9)
by
unknown
02:12
created

Ics::generate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 3
eloc 16
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
    $url = array('data:text/calendar;charset=utf8,',
12
      'BEGIN:VCALENDAR',
13
      'VERSION:2.0',
14
      'BEGIN:VEVENT',
15
      'DTSTART:' . $link->from->format('Ymd\THis'),
16
      'DTEND:' . $link->to->format('Ymd\THis'),
17
      'SUMMARY:' . $link->title);
18
19
    if ($link->description) {
20
      $url[] = 'DESCRIPTION:' . $link->description;
21
    }
22
    if ($link->address) {
23
      $url[] = 'LOCATION:' . str_replace(',', '', $link->address);
24
    }
25
26
    $url[] = 'END:VEVENT';
27
    $url[] = 'END:VCALENDAR';
28
    $redirectLink = join("\n", $url);
29
30
    return $redirectLink;
31
  }
32
}
33