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

VisibilityChangeHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 7
eloc 12
c 2
b 1
f 1
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 14 6
A __construct() 0 9 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 VisibilityChangeHandler implements \JsonSerializable
10
{
11
    /**
12
     * @param AbstractStandardCommand[] $commands list of commands to run (evaluated in order)
13
     * @param string|null $when APL boolean expression controlling whether this handler is considered. If null, treated as 'true'.
14
     * @param string|null $description optional description of this handler
15
     */
16 19
    public function __construct(
17
        public array $commands = [],
18
        public ?string $when = null,
19
        public ?string $description = null,
20
    ) {
21
        // Filter and ensure valid commands
22 19
        $this->commands = array_values(array_filter(
23 19
            $this->commands,
24 19
            static fn ($c) => $c instanceof AbstractStandardCommand
25 19
        ));
26
    }
27
28 12
    public function jsonSerialize(): array
29
    {
30 12
        $data = [];
31 12
        if ($this->commands !== []) {
32 6
            $data['commands'] = $this->commands;
33
        }
34 12
        if ($this->description !== null && $this->description !== '') {
35 6
            $data['description'] = $this->description;
36
        }
37 12
        if ($this->when !== null && $this->when !== '') {
38 6
            $data['when'] = $this->when;
39
        }
40
41 12
        return $data;
42
    }
43
}
44