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

InsertItemCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 1
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 21 6
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand;
6
7
class InsertItemCommand extends AbstractStandardCommand
8
{
9
    public const TYPE = 'InsertItem';
10
11
    /**
12
     * @param int|null $at Index where to insert the item
13
     * @param string|null $componentId The ID of the component to insert into
14
     * @param mixed $item Single item/component to insert (can be array, object, or APL component)
15
     * @param array|null $items Array of items/components to insert
16
     */
17 6
    public function __construct(
18
        public ?int $at = null,
19
        public ?string $componentId = null,
20
        public mixed $item = null,
21
        public ?array $items = null,
22
    ) {
23 6
        parent::__construct(self::TYPE);
24
    }
25
26 4
    public function jsonSerialize(): array
27
    {
28 4
        $data = parent::jsonSerialize();
29
30 4
        if ($this->at !== null) {
31 2
            $data['at'] = $this->at;
32
        }
33
34 4
        if ($this->componentId !== null) {
35 2
            $data['componentId'] = $this->componentId;
36
        }
37
38 4
        if ($this->item !== null) {
39 2
            $data['item'] = $this->item;
40
        }
41
42 4
        if ($this->items !== null && !empty($this->items)) {
43 2
            $data['items'] = $this->items;
44
        }
45
46 4
        return $data;
47
    }
48
}
49