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

AbstractRequest::setTime()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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