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

AbstractRequest::validateTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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