SwipeAway   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 1
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B jsonSerialize() 0 29 10
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\Component\APLBaseComponent;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\GestureType;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SwipeAction;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SwipeDirection;
11
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
12
13
class SwipeAway extends AbstractGesture
14
{
15
    /**
16
     * @param SwipeDirection|null $direction Direction the user swipes to activate the gesture
17
     * @param SwipeAction|null $action How to display the original and child components during the swipe gesture
18
     * @param APLBaseComponent|null $item Single item to display during and after the swipe gesture
19
     * @param APLBaseComponent[]|null $items Array of items to display during and after the swipe gesture
20
     * @param AbstractStandardCommand[]|null $onSwipeMove Commands to run as the swipe position changes
21
     * @param AbstractStandardCommand[]|null $onSwipeDone Commands to run when the swipe is complete
22
     * @param AbstractStandardCommand[]|null $onCancel Commands to run when gesture is cancelled
23
     * @param bool|null $when APL boolean expression controlling whether this gesture is active
24
     */
25 5
    public function __construct(
26
        public ?SwipeDirection $direction = null,
27
        public ?SwipeAction $action = null,
28
        public ?APLBaseComponent $item = null,
29
        public ?array $items = null,
30
        public ?array $onSwipeMove = null,
31
        public ?array $onSwipeDone = null,
32
        ?array $onCancel = null,
33
        ?bool $when = null,
34
    ) {
35 5
        parent::__construct(GestureType::SWIPE_AWAY, $onCancel, $when);
36
    }
37
38 3
    public function jsonSerialize(): array
39
    {
40 3
        $data = parent::jsonSerialize();
41
42 3
        if ($this->direction !== null) {
43 1
            $data['direction'] = $this->direction->value;
44
        }
45
46 3
        if ($this->action !== null) {
47 1
            $data['action'] = $this->action->value;
48
        }
49
50 3
        if ($this->item !== null) {
51 1
            $data['item'] = $this->item;
52
        }
53
54 3
        if ($this->items !== null && !empty($this->items)) {
55 1
            $data['items'] = $this->items;
56
        }
57
58 3
        if ($this->onSwipeMove !== null && !empty($this->onSwipeMove)) {
59 1
            $data['onSwipeMove'] = $this->onSwipeMove;
60
        }
61
62 3
        if ($this->onSwipeDone !== null && !empty($this->onSwipeDone)) {
63 1
            $data['onSwipeDone'] = $this->onSwipeDone;
64
        }
65
66 3
        return $data;
67
    }
68
}
69