SendIndexListDataDirective   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 59
ccs 21
cts 21
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 3 1
A __construct() 0 10 1
A jsonSerialize() 0 29 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\Directive;
8
9
class SendIndexListDataDirective extends Directive implements \JsonSerializable
10
{
11
    public const TYPE = 'Alexa.Presentation.APL.SendIndexListData';
12
13
    /**
14
     * @param string $listId The identifier for the list to update with this response
15
     * @param int $startIndex Index of the first element in the items array
16
     * @param string|null $correlationToken The correlation token supplied in the LoadIndexListData request
17
     * @param int|null $listVersion The new version number for the list following the update
18
     * @param string|null $minimumInclusiveIndex The index of the first item in the array
19
     * @param string|null $maximumExclusiveIndex The last valid index of the array plus one
20
     * @param array $items Array of objects to add to the list
21
     */
22 3
    public function __construct(
23
        public string $listId,
24
        public int $startIndex,
25
        public ?string $correlationToken = null,
26
        public ?int $listVersion = null,
27
        public ?string $minimumInclusiveIndex = null,
28
        public ?string $maximumExclusiveIndex = null,
29
        public array $items = [],
30
    ) {
31 3
        parent::__construct();
32
    }
33
34 1
    public function addItem(array $item): void
35
    {
36 1
        $this->items[] = $item;
37
    }
38
39 3
    public function jsonSerialize(): array
40
    {
41 3
        $data = [
42 3
            'type' => self::TYPE,
43 3
            'listId' => $this->listId,
44 3
            'startIndex' => $this->startIndex,
45 3
        ];
46
47 3
        if ($this->correlationToken !== null) {
48 1
            $data['correlationToken'] = $this->correlationToken;
49
        }
50
51 3
        if ($this->listVersion !== null) {
52 1
            $data['listVersion'] = $this->listVersion;
53
        }
54
55 3
        if ($this->minimumInclusiveIndex !== null) {
56 1
            $data['minimumInclusiveIndex'] = $this->minimumInclusiveIndex;
57
        }
58
59 3
        if ($this->maximumExclusiveIndex !== null) {
60 1
            $data['maximumExclusiveIndex'] = $this->maximumExclusiveIndex;
61
        }
62
63 3
        if (!empty($this->items)) {
64 1
            $data['items'] = $this->items;
65
        }
66
67 3
        return $data;
68
    }
69
}
70