Passed
Pull Request — master (#97)
by Maximilian
03:49
created

LoadIndexListDataRequest::fromAmazonRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 11
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
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 LoadIndexListDataRequest extends StandardRequest
12
{
13
    public const TYPE = 'Alexa.Presentation.APL.LoadIndexListData';
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|int|null $startIndex The lowest index of the items to fetch (inclusive)
23
     * @param int|null $count The number of items to fetch
24
     */
25 2
    public function __construct(
26
        ?\DateTime $timestamp = null,
27
        ?string $token = null,
28
        ?string $requestId = null,
29
        ?string $locale = null,
30
        public ?string $correlationToken = null,
31
        public ?string $listId = null,
32
        public string|int|null $startIndex = null,
33
        public ?int $count = null,
34
    ) {
35 2
        parent::__construct(
36 2
            type: self::TYPE,
37 2
            timestamp: $timestamp,
38 2
            token: $token,
39 2
            requestId: $requestId,
40 2
            locale: $locale
41 2
        );
42
    }
43
44 2
    public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
45
    {
46 2
        return new self(
47 2
            timestamp: self::getTime(PropertyHelper::checkNullValueStringOrInt($amazonRequest, 'timestamp')),
48 2
            token: PropertyHelper::checkNullValueString($amazonRequest, 'token'),
49 2
            requestId: PropertyHelper::checkNullValueString($amazonRequest, 'requestId'),
50 2
            locale: PropertyHelper::checkNullValueString($amazonRequest, 'locale'),
51 2
            correlationToken: PropertyHelper::checkNullValueString($amazonRequest, 'correlationToken'),
52 2
            listId: PropertyHelper::checkNullValueString($amazonRequest, 'listId'),
53 2
            startIndex: PropertyHelper::checkNullValueStringOrInt($amazonRequest, 'startIndex'),
54 2
            count: PropertyHelper::checkNullValueInt($amazonRequest, 'count'),
55 2
        );
56
    }
57
}
58