AlexaSkillEventRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
dl 0
loc 38
ccs 8
cts 10
cp 0.8
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTime() 0 7 2
A setRequestData() 0 9 1
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Request\Request\AlexaSkillEvent;
4
5
use MaxBeckers\AmazonAlexa\Request\Request\AbstractRequest;
6
7
/**
8
 * @author Maximilian Beckers <[email protected]>
9
 */
10
abstract class AlexaSkillEventRequest extends AbstractRequest
11
{
12
    /**
13
     * @var string
14
     */
15
    public $eventCreationTime;
16
17
    /**
18
     * @var string
19
     */
20
    public $eventPublishingTime;
21
22
    /**
23
     * @var string
24
     */
25
    public $requestId;
26
27
    /**
28
     * @param array $amazonRequest
29
     */
30 6
    protected function setRequestData(array $amazonRequest)
31
    {
32 6
        $this->requestId = $amazonRequest['requestId'];
33
34 6
        $this->setTime('timestamp', $amazonRequest['timeStamp']);
35 6
        $this->setTime('eventCreationTime', $amazonRequest['eventCreationTime']);
36 6
        $this->setTime('eventPublishingTime', $amazonRequest['eventPublishingTime']);
37
38 6
        $this->locale = $amazonRequest['locale'];
0 ignored issues
show
Bug Best Practice introduced by
The property locale does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
    }
40
41 6
    private function setTime($attribute, $value)
42
    {
43
        //Workaround for amazon developer console sending unix timestamp
44
        try {
45 6
            $this->{$attribute} = new \DateTime($value);
46
        } catch (\Exception $e) {
47
            $this->{$attribute} = (new \DateTime())->setTimestamp(intval($value / 1000));
48
        }
49
    }
50
}
51