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

DissectICalService::getEvents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
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\Ical;
5
6
use HDNET\Calendarize\Exception\UnableToGetEventsException;
7
use HDNET\Calendarize\Ical\DissectEventAdapter;
8
use HDNET\Calendarize\Service\AbstractService;
9
use JMBTechnologyLimited\ICalDissect\ICalEvent;
10
use JMBTechnologyLimited\ICalDissect\ICalParser;
11
12
class DissectICalService extends AbstractService implements ICalServiceInterface
13
{
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function getEvents(string $filename): array
19
    {
20
        $parser = new ICalParser();
21
        if (!$parser->parseFromFile($filename)) {
22
            throw new UnableToGetEventsException('Unable to open or parse "' . $filename . '".', 1602345343);
23
        }
24
        $events = $parser->getEvents();
25
26
        $wrapEvents = function (ICalEvent $event) {
27
            return new DissectEventAdapter($event);
28
        };
29
30
        return array_map($wrapEvents, $events);
31
    }
32
}
33