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

AVGItem::jsonSerialize()   B

Complexity

Conditions 9
Paths 64

Size

Total Lines 31
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 12.5599

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 9
eloc 15
nc 64
nop 0
dl 0
loc 31
ccs 11
cts 17
cp 0.6471
crap 12.5599
rs 8.0555
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGFilter\AVGFilter;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\AVGItemType;
9
10
abstract class AVGItem implements \JsonSerializable
11
{
12
    /**
13
     * @param AVGItemType $type Type of the AVG item
14
     * @param array|null $bind Array of binding objects
15
     * @param string|null $description Description of this item
16
     * @param AVGFilter|null $filter Single filter to apply
17
     * @param AVGFilter[]|null $filters Array of filters to apply
18
     * @param string|null $style Style to apply
19
     * @param bool|null $when Condition for rendering this item
20
     */
21 32
    public function __construct(
22
        public AVGItemType $type,
23
        public ?array $bind = null,
24
        public ?string $description = null,
25
        public ?AVGFilter $filter = null,
26
        public ?array $filters = null,
27
        public ?string $style = null,
28
        public ?bool $when = null,
29
    ) {
30 32
    }
31
32 20
    public function jsonSerialize(): array
33
    {
34 20
        $data = [
35 20
            'type' => $this->type->value,
36 20
        ];
37
38 20
        if ($this->bind !== null && !empty($this->bind)) {
39
            $data['bind'] = $this->bind;
40
        }
41
42 20
        if ($this->description !== null) {
43
            $data['description'] = $this->description;
44
        }
45
46 20
        if ($this->filter !== null) {
47
            $data['filter'] = $this->filter;
48
        }
49
50 20
        if ($this->filters !== null && !empty($this->filters)) {
51
            $data['filters'] = $this->filters;
52
        }
53
54 20
        if ($this->style !== null) {
55
            $data['style'] = $this->style;
56
        }
57
58 20
        if ($this->when !== null) {
59
            $data['when'] = $this->when;
60
        }
61
62 20
        return $data;
63
    }
64
}
65