Passed
Pull Request — master (#97)
by Maximilian
03:49
created

AbstractGesture   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A jsonSerialize() 0 15 4
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
abstract class AbstractGesture implements \JsonSerializable
11
{
12
    /**
13
     * @param GestureType $type The type of gesture
14
     * @param AbstractStandardCommand[]|null $onCancel Commands to run when gesture is cancelled
15
     * @param bool|null $when APL boolean expression controlling whether this gesture is active
16
     */
17 20
    public function __construct(
18
        public GestureType $type,
19
        public ?array $onCancel = null,
20
        public ?bool $when = null,
21
    ) {
22 20
    }
23
24 12
    public function jsonSerialize(): array
25
    {
26 12
        $data = [
27 12
            'type' => $this->type->value,
28 12
        ];
29
30 12
        if ($this->onCancel !== null && !empty($this->onCancel)) {
31 3
            $data['onCancel'] = $this->onCancel;
32
        }
33
34 12
        if ($this->when !== null) {
35 3
            $data['when'] = $this->when;
36
        }
37
38 12
        return $data;
39
    }
40
}
41