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

Ics   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 22 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
    $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