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

DissectICalService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

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