IntentRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
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 6
dl 0
loc 14
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\Standard;
6
7
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper;
8
use MaxBeckers\AmazonAlexa\Intent\Intent;
9
use MaxBeckers\AmazonAlexa\Request\Request\AbstractRequest;
10
11
class IntentRequest extends StandardRequest
12
{
13
    public const DIALOG_STATE_STARTED = 'STARTED';
14
    public const DIALOG_STATE_IN_PROGRESS = 'IN_PROGRESS';
15
    public const DIALOG_STATE_COMPLETED = 'COMPLETED';
16
17
    public const TYPE = 'IntentRequest';
18
19
    /**
20
     * @param \DateTime|null $timestamp Request timestamp
21
     * @param string|null $token Request token
22
     * @param string|null $requestId Request identifier
23
     * @param string|null $locale Request locale
24
     * @param string|null $dialogState Current dialog state
25
     * @param Intent|null $intent Intent information
26
     */
27 29
    public function __construct(
28
        ?\DateTime $timestamp = null,
29
        ?string $token = null,
30
        ?string $requestId = null,
31
        ?string $locale = null,
32
        public ?string $dialogState = null,
33
        public ?Intent $intent = null,
34
    ) {
35 29
        parent::__construct(
36 29
            type: static::TYPE,
37 29
            timestamp: $timestamp,
38 29
            token: $token,
39 29
            requestId: $requestId,
40 29
            locale: $locale
41 29
        );
42
    }
43
44 19
    public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
45
    {
46 19
        return new static(
47 19
            timestamp: self::getTime(PropertyHelper::checkNullValueStringOrInt($amazonRequest, 'timestamp')),
48 19
            requestId: PropertyHelper::checkNullValueString($amazonRequest, 'requestId'),
49 19
            locale: PropertyHelper::checkNullValueString($amazonRequest, 'locale'),
50 19
            dialogState: PropertyHelper::checkNullValueString($amazonRequest, 'dialogState'),
51 19
            intent: Intent::fromAmazonRequest($amazonRequest['intent']),
52 19
        );
53
    }
54
}
55