AlexaPresentationAPL   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromAmazonRequest() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Request;
6
7
class AlexaPresentationAPL
8
{
9
    /**
10
     * @param string|null $token APL token
11
     * @param string|null $version APL version
12
     * @param ComponentVisibleOnScreen[]|null $componentsVisibleOnScreen Array of visible components
13
     */
14 2
    public function __construct(
15
        public ?string $token = null,
16
        public ?string $version = null,
17
        public ?array $componentsVisibleOnScreen = null,
18
    ) {
19 2
    }
20
21 2
    public static function fromAmazonRequest(array $amazonRequest): self
22
    {
23 2
        $componentsVisibleOnScreen = null;
24 2
        if (isset($amazonRequest['componentsVisibleOnScreen']) && is_array($amazonRequest['componentsVisibleOnScreen'])) {
25 2
            $componentsVisibleOnScreen = [];
26 2
            foreach ($amazonRequest['componentsVisibleOnScreen'] as $componentData) {
27 2
                $componentsVisibleOnScreen[] = ComponentVisibleOnScreen::fromAmazonRequest($componentData);
28
            }
29
        }
30
31 2
        return new self(
32 2
            token: $amazonRequest['token'] ?? null,
33 2
            version: $amazonRequest['version'] ?? null,
34 2
            componentsVisibleOnScreen: $componentsVisibleOnScreen,
35 2
        );
36
    }
37
}
38