Resolution   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 23
dl 0
loc 45
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 19 5
A fromAmazonRequest() 0 16 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Intent;
6
7
class Resolution implements \JsonSerializable
8
{
9
    public ?string $authority = null;
10
    public ?IntentStatus $status = null;
11
12
    /** @var IntentValue[] */
13
    public array $values = [];
14
15 9
    public static function fromAmazonRequest(array $amazonRequest): self
16
    {
17 9
        $resolution = new self();
18
19 9
        $resolution->authority = $amazonRequest['authority'] ?? null;
20 9
        $resolution->status = isset($amazonRequest['status']) ? IntentStatus::fromAmazonRequest($amazonRequest['status']) : null;
21
22 9
        if (isset($amazonRequest['values'])) {
23 9
            foreach ($amazonRequest['values'] as $value) {
24 9
                if (isset($value['value'])) {
25 9
                    $resolution->values[] = IntentValue::fromAmazonRequest($value['value']);
26
                }
27
            }
28
        }
29
30 9
        return $resolution;
31
    }
32
33 3
    public function jsonSerialize(): array
34
    {
35 3
        $data = [];
36 3
        if ($this->authority) {
37 3
            $data['authority'] = $this->authority;
38
        }
39 3
        if ($this->status) {
40 3
            $data['status'] = $this->status;
41
        }
42 3
        if (!empty($this->values)) {
43 3
            $data['values'] = [];
44 3
            foreach ($this->values as $value) {
45 3
                $data['values'][] = [
46 3
                    'value' => $value,
47 3
                ];
48
            }
49
        }
50
51 3
        return $data;
52
    }
53
}
54