PlaybackStartedRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 5
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Request\Request\AudioPlayer;
6
7
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper;
8
use MaxBeckers\AmazonAlexa\Request\Request\AbstractRequest;
9
10
class PlaybackStartedRequest extends AudioPlayerRequest
11
{
12
    public const TYPE = 'AudioPlayer.PlaybackStarted';
13
14
    /**
15
     * @param \DateTime|null $timestamp Request timestamp
16
     * @param string|null $token Audio player token
17
     * @param string|null $requestId Request identifier
18
     * @param string|null $locale Request locale
19
     * @param int|null $offsetInMilliseconds Playback offset in milliseconds
20
     */
21 1
    public function __construct(
22
        ?\DateTime $timestamp = null,
23
        ?string $token = null,
24
        ?string $requestId = null,
25
        ?string $locale = null,
26
        public ?int $offsetInMilliseconds = null,
27
    ) {
28 1
        parent::__construct(
29 1
            type: self::TYPE,
30 1
            timestamp: $timestamp,
31 1
            token: $token,
32 1
            requestId: $requestId,
33 1
            locale: $locale
34 1
        );
35
    }
36
37 1
    public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
38
    {
39 1
        return new self(
40 1
            timestamp: self::getTime(PropertyHelper::checkNullValueStringOrInt($amazonRequest, 'timestamp')),
41 1
            token: PropertyHelper::checkNullValueString($amazonRequest, 'token'),
42 1
            requestId: PropertyHelper::checkNullValueString($amazonRequest, 'requestId'),
43 1
            locale: PropertyHelper::checkNullValueString($amazonRequest, 'locale'),
44 1
            offsetInMilliseconds: PropertyHelper::checkNullValueInt($amazonRequest, 'offsetInMilliseconds'),
45 1
        );
46
    }
47
}
48