Passed
Push — master ( b464b5...fd08ce )
by Maximilian
45s queued 11s
created

Geolocation::fromAmazonRequest()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 9.2222
c 0
b 0
f 0
cc 6
nc 32
nop 1
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Request;
4
5
/**
6
 * @author Brandon Olivares <[email protected]>
7
 */
8
class Geolocation
9
{
10
    /**
11
     * @var LocationServices|null
12
     */
13
    public $locationServices;
14
15
    /**
16
     * @var \DateTime
17
     */
18
    public $timestamp;
19
20
    /**
21
     * @var Coordinate|null
22
     */
23
    public $coordinate;
24
25
    /**
26
     * @var Altitude|null
27
     */
28
    public $altitude;
29
30
    /**
31
     * @var Heading|null
32
     */
33
    public $heading;
34
35
    /**
36
     * @var Speed|null
37
     */
38
    public $speed;
39
40
    /**
41
     * @param array $amazonRequest
42
     *
43
     * @return Geolocation
44
     */
45
    public static function fromAmazonRequest(array $amazonRequest): self
46
    {
47
        $geolocation = new self();
48
49
        $geolocation->locationServices  = isset($amazonRequest['locationServices']) ? LocationServices::fromAmazonRequest($amazonRequest['locationServices']) : null;
50
        $geolocation->timestamp         = new \DateTime($amazonRequest['timestamp']);
51
        $geolocation->coordinate        = isset($amazonRequest['coordinate']) ? Coordinate::fromAmazonRequest($amazonRequest['coordinate']) : null;
52
        $geolocation->altitude          = isset($amazonRequest['altitude']) ? Altitude::fromAmazonRequest($amazonRequest['altitude']) : null;
53
        $geolocation->heading           = isset($amazonRequest['heading']) ? Heading::fromAmazonRequest($amazonRequest['heading']) : null;
54
        $geolocation->speed             = isset($amazonRequest['speed']) ? Speed::fromAmazonRequest($amazonRequest['speed']) : null;
55
56
        return $geolocation;
57
    }
58
}
59