TickHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
dl 0
loc 41
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 1
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A jsonSerialize() 0 18 6
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 TickHandler implements \JsonSerializable
10
{
11
    public const DEFAULT_MINIMUM_DELAY = 1000;
12
13
    /**
14
     * @param AbstractStandardCommand[] $commands Commands to run during tick events
15
     * @param string|null $when APL boolean expression controlling whether the handler is active. Null means always active.
16
     * @param string $description Optional description of this handler
17
     * @param int $minimumDelay Minimum delay between tick events in milliseconds
18
     */
19 17
    public function __construct(
20
        public array $commands = [],
21
        public ?string $when = null,
22
        public string $description = '',
23
        public int $minimumDelay = self::DEFAULT_MINIMUM_DELAY,
24
    ) {
25
        // Filter and ensure valid commands
26 17
        $this->commands = array_values(array_filter(
27 17
            $this->commands,
28 17
            static fn ($c) => $c instanceof AbstractStandardCommand
29 17
        ));
30
    }
31
32 11
    public function jsonSerialize(): array
33
    {
34 11
        $data = [];
35
36 11
        if ($this->commands !== []) {
37 2
            $data['commands'] = $this->commands;
38
        }
39 11
        if ($this->description !== '') {
40 6
            $data['description'] = $this->description;
41
        }
42 11
        if ($this->minimumDelay !== self::DEFAULT_MINIMUM_DELAY) {
43 6
            $data['minimumDelay'] = $this->minimumDelay;
44
        }
45 11
        if ($this->when !== null && $this->when !== '') {
46 4
            $data['when'] = $this->when;
47
        }
48
49 11
        return $data;
50
    }
51
}
52