LongPress::jsonSerialize()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 6
nc 4
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 5
rs 9.6111
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Gesture;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\GestureType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
9
10
class LongPress extends AbstractGesture
11
{
12
    /**
13
     * @param AbstractStandardCommand[]|null $onLongPressStart Commands to run when long press starts
14
     * @param AbstractStandardCommand[]|null $onLongPressEnd Commands to run when long press ends
15
     * @param AbstractStandardCommand[]|null $onCancel Commands to run when gesture is cancelled
16
     * @param bool|null $when APL boolean expression controlling whether this gesture is active
17
     */
18 5
    public function __construct(
19
        public ?array $onLongPressStart = null,
20
        public ?array $onLongPressEnd = null,
21
        ?array $onCancel = null,
22
        ?bool $when = null,
23
    ) {
24 5
        parent::__construct(GestureType::LONG_PRESS, $onCancel, $when);
25
    }
26
27 3
    public function jsonSerialize(): array
28
    {
29 3
        $data = parent::jsonSerialize();
30
31 3
        if ($this->onLongPressStart !== null && !empty($this->onLongPressStart)) {
32 1
            $data['onLongPressStart'] = $this->onLongPressStart;
33
        }
34
35 3
        if ($this->onLongPressEnd !== null && !empty($this->onLongPressEnd)) {
36 1
            $data['onLongPressEnd'] = $this->onLongPressEnd;
37
        }
38
39 3
        return $data;
40
    }
41
}
42