KeyHandler::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
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 KeyHandler implements \JsonSerializable
10
{
11
    /**
12
     * @param AbstractStandardCommand[] $commands Commands to run when handler applies
13
     * @param bool $propagate Whether to propagate the event after handling
14
     * @param string|null $when APL boolean expression controlling whether this handler is considered
15
     */
16 14
    public function __construct(
17
        public array $commands = [],
18
        public bool $propagate = false,
19
        public ?string $when = null,
20
    ) {
21 14
    }
22
23 10
    public function jsonSerialize(): array
24
    {
25 10
        return array_filter([
26 10
            'commands' => $this->commands,
27 10
            'propagate' => $this->propagate,
28 10
            'when' => $this->when,
29 10
        ], fn ($value) => $value !== null);
30
    }
31
}
32