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

TouchableComponent::jsonSerialize()   C

Complexity

Conditions 14
Paths 128

Size

Total Lines 33
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 27.6872

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 14
eloc 16
nc 128
nop 0
dl 0
loc 33
ccs 10
cts 17
cp 0.5881
crap 27.6872
rs 6.0333
c 1
b 0
f 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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