Completed
Pull Request — master (#443)
by
unknown
02:03
created

DissectICalService::getEvents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
namespace HDNET\Calendarize\Service;
5
6
use HDNET\Calendarize\Domain\DissectEvent;
7
use JMBTechnologyLimited\ICalDissect\ICalEvent;
8
use JMBTechnologyLimited\ICalDissect\ICalParser;
9
10
class DissectICalService extends AbstractService implements ICalServiceInterface
11
{
12
13
    /**
14
     * @inheritDoc
15
     */
16
    public function getEvents(string $filename): array
17
    {
18
        $parser = new ICalParser();
19
        if (!$parser->parseFromFile($filename)) {
20
            // TODO: FileNotFoundException
21
            throw new \RuntimeException('Unable to open or parse "' . $filename . '".', 1602345343);
22
        }
23
        // TODO: handle timezone???
24
        $events = $parser->getEvents();
25
26
        $wrapEvents = function (ICalEvent $event) {
27
            return new DissectEvent($event);
28
        };
29
30
        return array_map($wrapEvents, $events);
31
    }
32
}
33