Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

DoublePress   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 1
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A jsonSerialize() 0 13 5
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 DoublePress extends AbstractGesture
11
{
12
    /**
13
     * @param AbstractStandardCommand[]|null $onDoublePress Commands to run on double press
14
     * @param AbstractStandardCommand[]|null $onSinglePress Commands to run on single press
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 $onDoublePress = null,
20
        public ?array $onSinglePress = null,
21
        ?array $onCancel = null,
22
        ?bool $when = null,
23
    ) {
24 5
        parent::__construct(GestureType::DOUBLE_PRESS, $onCancel, $when);
25
    }
26
27 3
    public function jsonSerialize(): array
28
    {
29 3
        $data = parent::jsonSerialize();
30
31 3
        if ($this->onDoublePress !== null && !empty($this->onDoublePress)) {
32 1
            $data['onDoublePress'] = $this->onDoublePress;
33
        }
34
35 3
        if ($this->onSinglePress !== null && !empty($this->onSinglePress)) {
36 1
            $data['onSinglePress'] = $this->onSinglePress;
37
        }
38
39 3
        return $data;
40
    }
41
}
42