IntentRequest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromAmazonRequest() 0 8 1
A __construct() 0 14 1
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