Passed
Pull Request — master (#97)
by Maximilian
04:02
created

LoadTokenListDataRequest::fromAmazonRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Request\Request\APL;
6
7
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper;
8
use MaxBeckers\AmazonAlexa\Request\Request\AbstractRequest;
9
use MaxBeckers\AmazonAlexa\Request\Request\Standard\StandardRequest;
10
11
class LoadTokenListDataRequest extends StandardRequest
12
{
13
    public const TYPE = 'Alexa.Presentation.APL.LoadTokenListData';
14
15
    /**
16
     * @param \DateTime|null $timestamp Request timestamp
17
     * @param string|null $token The presentation token specified in the RenderDocument directive
18
     * @param string|null $requestId Request identifier
19
     * @param string|null $locale Request locale
20
     * @param string|null $correlationToken Alexa-generated identifier used to correlate requests with response directives
21
     * @param string|null $listId The identifier of the list for which to fetch items
22
     * @param string|null $pageToken A token associated with the items to fetch
23
     */
24 1
    public function __construct(
25
        ?\DateTime $timestamp = null,
26
        ?string $token = null,
27
        ?string $requestId = null,
28
        ?string $locale = null,
29
        public ?string $correlationToken = null,
30
        public ?string $listId = null,
31
        public ?string $pageToken = null,
32
    ) {
33 1
        parent::__construct(
34 1
            type: self::TYPE,
35 1
            timestamp: $timestamp,
36 1
            token: $token,
37 1
            requestId: $requestId,
38 1
            locale: $locale
39 1
        );
40
    }
41
42 1
    public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
43
    {
44 1
        return new self(
45 1
            timestamp: self::getTime(PropertyHelper::checkNullValueStringOrInt($amazonRequest, 'timestamp')),
46 1
            token: PropertyHelper::checkNullValueString($amazonRequest, 'token'),
47 1
            requestId: PropertyHelper::checkNullValueString($amazonRequest, 'requestId'),
48 1
            locale: PropertyHelper::checkNullValueString($amazonRequest, 'locale'),
49 1
            correlationToken: PropertyHelper::checkNullValueString($amazonRequest, 'correlationToken'),
50 1
            listId: PropertyHelper::checkNullValueString($amazonRequest, 'listId'),
51 1
            pageToken: PropertyHelper::checkNullValueString($amazonRequest, 'pageToken'),
52 1
        );
53
    }
54
}
55