Passed
Push — master ( 4b2c1a...a53d55 )
by Maximilian
02:53
created

AbstractRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setTime() 0 8 3
A validateSignature() 0 3 1
A validateTimestamp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Request\Request;
6
7
abstract class AbstractRequest
8
{
9
    public string $type;
10
    public \DateTime $timestamp;
11
12
    abstract public static function fromAmazonRequest(array $amazonRequest): self;
13
14 4
    public function validateTimestamp(): bool
15
    {
16 4
        return true;
17
    }
18
19 46
    public function validateSignature(): bool
20
    {
21 46
        return true;
22
    }
23
24 44
    protected function setTime(string $attribute, string|int|null $value): void
25
    {
26 44
        if ($value !== null) {
27
            // Workaround for amazon developer console sending unix timestamp
28
            try {
29 44
                $this->{$attribute} = new \DateTime((string) $value);
30 14
            } catch (\Exception $e) {
31 14
                $this->{$attribute} = (new \DateTime())->setTimestamp((int) ((string) ($value / 1000)));
32
            }
33
        }
34
    }
35
}
36