Passed
Pull Request — master (#97)
by Maximilian
04:02
created

TouchableComponent   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 63.16%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
dl 0
loc 58
ccs 12
cts 19
cp 0.6316
rs 10
c 1
b 0
f 1
wmc 15

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
C jsonSerialize() 0 33 14
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Gesture\AbstractGesture;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
10
11
abstract class TouchableComponent extends ActionableComponent implements \JsonSerializable
12
{
13
    /**
14
     * @param APLComponentType $type The type of the component
15
     * @param AbstractGesture|null $gesture Single gesture handler
16
     * @param AbstractGesture[]|null $gestures Array of gesture handlers
17
     * @param AbstractStandardCommand[]|null $onCancel Commands to run when a gesture takes over the pointer
18
     * @param AbstractStandardCommand[]|null $onDown Commands to run when a pointer down event occurs
19
     * @param AbstractStandardCommand[]|null $onMove Commands to run as the pointer moves
20
     * @param AbstractStandardCommand[]|null $onPress Commands to run for a pointer down followed by a pointer up
21
     * @param AbstractStandardCommand[]|null $onUp Commands to run when releasing the pointer
22
     */
23 19
    public function __construct(
24
        APLComponentType $type,
25
        public ?AbstractGesture $gesture = null,
26
        public ?array $gestures = null,
27
        public ?array $onCancel = null,
28
        public ?array $onDown = null,
29
        public ?array $onMove = null,
30
        public ?array $onPress = null,
31
        public ?array $onUp = null,
32
    ) {
33 19
        parent::__construct($type);
34
    }
35
36 11
    public function jsonSerialize(): array
37
    {
38 11
        $data = parent::jsonSerialize();
39
40 11
        if ($this->gesture !== null) {
41
            $data['gesture'] = $this->gesture;
42
        }
43
44 11
        if ($this->gestures !== null && !empty($this->gestures)) {
45
            $data['gestures'] = $this->gestures;
46
        }
47
48 11
        if ($this->onCancel !== null && !empty($this->onCancel)) {
49
            $data['onCancel'] = $this->onCancel;
50
        }
51
52 11
        if ($this->onDown !== null && !empty($this->onDown)) {
53
            $data['onDown'] = $this->onDown;
54
        }
55
56 11
        if ($this->onMove !== null && !empty($this->onMove)) {
57
            $data['onMove'] = $this->onMove;
58
        }
59
60 11
        if ($this->onPress !== null && !empty($this->onPress)) {
61
            $data['onPress'] = $this->onPress;
62
        }
63
64 11
        if ($this->onUp !== null && !empty($this->onUp)) {
65
            $data['onUp'] = $this->onUp;
66
        }
67
68 11
        return $data;
69
    }
70
}
71