Passed
Pull Request — master (#97)
by Maximilian
04:02
created

ExecuteCommandsDirective   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 16 3
A __construct() 0 5 1
A addCommand() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
8
use MaxBeckers\AmazonAlexa\Response\Directives\Directive;
9
10
class ExecuteCommandsDirective extends Directive implements \JsonSerializable
11
{
12
    public const TYPE = 'Alexa.Presentation.APL.ExecuteCommands';
13
14
    /**
15
     * @param AbstractStandardCommand[] $commands Commands to run on the rendered document
16
     * @param string|null $token Token that identifies the RenderDocument command (for standard APL documents)
17
     * @param string|null $presentationUri String that identifies the widget to target with commands
18
     */
19
    public function __construct(
20
        public array $commands,
21
        public ?string $token = null,
22
        public ?string $presentationUri = null,
23
    ) {
24
    }
25
26
    public function addCommand(AbstractStandardCommand $command): void
27
    {
28
        $this->commands[] = $command;
29
    }
30
31
    public function jsonSerialize(): array
32
    {
33
        $data = [
34
            'type' => self::TYPE,
35
            'commands' => $this->commands,
36
        ];
37
38
        if ($this->token !== null) {
39
            $data['token'] = $this->token;
40
        }
41
42
        if ($this->presentationUri !== null) {
43
            $data['presentationUri'] = $this->presentationUri;
44
        }
45
46
        return $data;
47
    }
48
}
49