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

DissectICalService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getEvents() 0 16 2
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