APLDocument::setLayout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Document;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
8
9
class APLDocument implements \JsonSerializable
10
{
11
    /**
12
     * @param MainTemplate $mainTemplate The main template that defines the layout to inflate when the document first displays
13
     * @param string $type The type of the document, must be "APL"
14
     * @param string $version The APL version this document uses
15
     * @param Gradient|string|null $background Background fill that allows either a color or gradient
16
     * @param array<string, Command>|null $commands Map of command name to Command objects for user-defined commands
17
     * @param string|null $description Optional description of this APL document
18
     * @param Environment|null $environment Environment settings like language and layout direction
19
     * @param Export|null $export Definitions to export for use by other documents
20
     * @param Extension[]|null $extensions Array of Extension objects to load additional functionality
21
     * @param Graphic[]|null $graphics Array of Graphic objects in Alexa Vector Graphics format
22
     * @param KeyHandler[]|null $handleKeyDown Array of KeyHandler objects for key down events
23
     * @param KeyHandler[]|null $handleKeyUp Array of KeyHandler objects for key up events
24
     * @param TickHandler[]|null $handleTick Array of TickHandler objects for time-based events
25
     * @param Import[]|null $import Array of Import objects for external packages
26
     * @param array<string, Layout> $layouts Map of layout name to Layout objects for reusable layouts
27
     * @param AbstractStandardCommand|null $onConfigChange Commands to run when document configuration changes
28
     * @param AbstractStandardCommand[]|null $onDisplayStateChange Array of commands to run when display state changes
29
     * @param AbstractStandardCommand|null $onMount Commands to run when document is first displayed
30
     * @param resource[]|null $resources Array of Resource objects for document-wide resources
31
     * @param Settings|null $settings Document-wide settings like idle timeout
32
     * @param Style[]|null $styles Array of Style objects for reusable styling
33
     * @param string|null $theme Theme name to apply to the document
34
     */
35 25
    public function __construct(
36
        public MainTemplate $mainTemplate,
37
        public string $type = 'APL',
38
        public string $version = '2024.3',
39
        public Gradient|string|null $background = null,
40
        public ?array $commands = null,
41
        public ?string $description = null,
42
        public ?Environment $environment = null,
43
        public ?Export $export = null,
44
        public ?array $extensions = null,
45
        public ?array $graphics = null,
46
        public ?array $handleKeyDown = null,
47
        public ?array $handleKeyUp = null,
48
        public ?array $handleTick = null,
49
        public ?array $import = null,
50
        public array $layouts = [],
51
        public ?AbstractStandardCommand $onConfigChange = null,
52
        public ?array $onDisplayStateChange = null,
53
        public ?AbstractStandardCommand $onMount = null,
54
        public ?array $resources = null,
55
        public ?Settings $settings = null,
56
        public ?array $styles = null,
57
        public ?string $theme = null,
58
    ) {
59 25
    }
60
61
    public function setLayout(string $name, Layout $layout): void
62
    {
63
        $this->layouts[$name] = $layout;
64
    }
65
66 2
    public function jsonSerialize(): array
67
    {
68 2
        return array_filter(get_object_vars($this), function ($val) {
69 2
            if (is_array($val)) {
70 2
                return count($val) > 0;
71
            }
72
73 2
            return $val !== null;
74 2
        });
75
    }
76
}
77