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

SequenceComponent   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
dl 0
loc 53
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 1
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B jsonSerialize() 0 29 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component;
6
7
use MaxBeckers\AmazonAlexa\Request\ScrollDirection;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\ActionableComponentTrait;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\MultiChildComponentTrait;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
11
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Snap;
12
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
13
14
class SequenceComponent extends APLBaseComponent implements \JsonSerializable
15
{
16
    use ActionableComponentTrait;
17
    use MultiChildComponentTrait;
18
19
    public const TYPE = APLComponentType::SEQUENCE;
20
21
    /**
22
     * @param bool $numbered When true, assign ordinal numbers to the Sequence children
23
     * @param AbstractStandardCommand[]|null $onScroll Commands to run during scrolling
24
     * @param string[]|null $preserve Properties to save when reinflating the document
25
     * @param ScrollDirection|null $scrollDirection The direction to scroll this Sequence
26
     * @param Snap|null $snap The alignment that the child components snap to when scrolling stops
27
     */
28 13
    public function __construct(
29
        public bool $numbered = false,
30
        public ?array $onScroll = null,
31
        ?array $preserve = null,
32
        public ?ScrollDirection $scrollDirection = null,
33
        public ?Snap $snap = null,
34
    ) {
35 13
        parent::__construct(type: self::TYPE, preserve: $preserve);
36
    }
37
38 7
    public function jsonSerialize(): array
39
    {
40 7
        $data = array_merge(
41 7
            parent::jsonSerialize(),
42 7
            $this->serializeActionableProperties(),
43 7
            $this->serializeMultiChildProperties()
44 7
        );
45
46 7
        if ($this->numbered) {
47 2
            $data['numbered'] = $this->numbered;
48
        }
49
50 7
        if ($this->onScroll !== null && !empty($this->onScroll)) {
51 1
            $data['onScroll'] = $this->onScroll;
52
        }
53
54 7
        if ($this->preserve !== null && !empty($this->preserve)) {
55 1
            $data['preserve'] = $this->preserve;
56
        }
57
58 7
        if ($this->scrollDirection !== null) {
59 2
            $data['scrollDirection'] = $this->scrollDirection->value;
60
        }
61
62 7
        if ($this->snap !== null) {
63 2
            $data['snap'] = $this->snap->value;
64
        }
65
66 7
        return $data;
67
    }
68
}
69