Completed
Push — master ( d89681...8e123d )
by Andreas
20s
created

ConferenceParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __invoke() 0 43 3
1
<?php
2
3
/*
4
 * Copyright (c) Andreas Heigl<[email protected]
5
 *
6
 * Licensed under the MIT License. See LICENSE.md file in the project root
7
 * for full license information.
8
 */
9
10
namespace Callingallpapers\Parser\ConfsTech;
11
12
use Callingallpapers\Entity\Cfp;
13
use Callingallpapers\Service\GeolocationService;
14
use Callingallpapers\Service\TimezoneService;
15
use DateTimeImmutable;
16
use DateTimeZone;
17
18
class ConferenceParser
19
{
20
    private $geolocation;
21
22
    private $timezone;
23
24
    public function __construct(
25
        GeolocationService $geolocation,
26
        TimezoneService $timezone
27
    ) {
28
        $this->geolocation = $geolocation;
29
        $this->timezone    = $timezone;
30
    }
31
32
    public function __invoke(array $conference) : Cfp
33
    {
34
        $cfp = new Cfp();
35
        $cfp->location = $conference['city'];
36
37
        $geolocation = $this->geolocation->getLocationForAddress(
38
            $conference['country'] . ', ' . $cfp->location
39
        );
40
41
        $cfp->latitude = $geolocation->getLatitude();
42
        $cfp->longitude = $geolocation->getLongitude();
43
44
        $cfp->timezone = $this->timezone->getTimezoneForLocation(
45
            $cfp->latitude,
46
            $cfp->longitude
47
        );
48
49
        $cfp->conferenceName = $conference['name'];
50
        $cfp->eventStartDate = new DateTimeImmutable(
51
            $conference['startDate'] . ' 08:00:00',
52
            new DateTimeZone($cfp->timezone)
53
        );
54
        if (! isset($conference['endDate'])) {
55
            $conference['endDate'] = $conference['startDate'];
56
        }
57
        $cfp->eventEndDate = new DateTimeImmutable(
58
            $conference['endDate'] . ' 17:00:00',
59
            new DateTimeZone($cfp->timezone)
60
        );
61
62
        $cfp->dateEnd = new DateTimeImmutable(
63
            $conference['cfpEndDate'] . ' 23:59:59',
64
            new DateTimeZone($cfp->timezone)
65
        );
66
67
        $cfp->conferenceUri = $conference['url'];
68
        $cfp->uri = $conference['url'];
69
        if (isset($conference['cfpUrl'])) {
70
            $cfp->uri = $conference['cfpUrl'];
71
        }
72
73
        return $cfp;
74
    }
75
}
76