ICSExporter::exportEvent()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 9.568
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shapin\Calendar;
6
7
use Sabre\VObject;
8
use Shapin\Calendar\Model\Calendar;
9
use Shapin\Calendar\Model\Event;
10
use Shapin\Calendar\Model\RecurrenceRule;
11
12
class ICSExporter
13
{
14 2
    public function exportEvent(Event $event): string
15
    {
16
        $data = [
17 2
            'SUMMARY' => $event->getSummary(),
18 2
            'DESCRIPTION' => $event->getDescription(),
19 2
            'DTSTART' => $event->getStartAt(),
20 2
            'DTEND'   => $event->getEndAt(),
21
        ];
22 2
        if (null !== $event->getClassification()) {
23 1
            $data['CLASS'] = $event->getClassification();
24
        }
25
26 2
        if ($event->isRecurring()) {
27 1
            $data['RRULE'] = $event->getRecurrenceRule()->getParts();
28
        }
29
30 2
        $vcalendar = new VObject\Component\VCalendar([
31 2
            'VEVENT' => $data,
32
        ]);
33
34 2
        return $vcalendar->serialize();
35
    }
36
}
37