RuntimeErrorRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromAmazonRequest() 0 12 4
A validateTimestamp() 0 3 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
10
class RuntimeErrorRequest extends AbstractRequest
11
{
12
    public const TYPE = 'Alexa.Presentation.APL.RuntimeError';
13
14
    /**
15
     * @param string|null $token The presentation token specified in the RenderDocument directive
16
     * @param array $errors An array of reported errors
17
     */
18 2
    public function __construct(
19
        public ?string $token = null,
20
        public array $errors = [],
21
    ) {
22 2
        parent::__construct(type: self::TYPE);
23
    }
24
25 2
    public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
26
    {
27 2
        $errors = [];
28 2
        if (isset($amazonRequest['errors']) && is_array($amazonRequest['errors'])) {
29 2
            foreach ($amazonRequest['errors'] as $errorData) {
30 2
                $errors[] = RuntimeError::fromAmazonRequest($errorData);
31
            }
32
        }
33
34 2
        return new self(
35 2
            token: PropertyHelper::checkNullValueString($amazonRequest, 'token'),
36 2
            errors: $errors,
37 2
        );
38
    }
39
40 1
    public function validateTimestamp(): bool
41
    {
42 1
        return false;
43
    }
44
}
45