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

Group::jsonSerialize()   B

Complexity

Conditions 9
Paths 64

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 9
eloc 14
nc 64
nop 0
dl 0
loc 29
ccs 15
cts 15
cp 1
crap 9
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\Document\AVGItemType;
8
9
class Group extends AVGItem implements \JsonSerializable
10
{
11
    public const TYPE = AVGItemType::GROUP;
12
13
    /**
14
     * @param string|null $clipPath Clipping path for the group
15
     * @param array|null $data Array of data for inflation
16
     * @param AVGItem|null $item Single child item
17
     * @param AVGItem[]|null $items Array of child items
18
     * @param float|null $opacity Opacity of the group
19
     * @param string|null $transform Transform to apply to the group
20
     */
21 10
    public function __construct(
22
        public ?string $clipPath = null,
23
        public ?array $data = null,
24
        public ?AVGItem $item = null,
25
        public ?array $items = null,
26
        public ?float $opacity = null,
27
        public ?string $transform = null,
28
    ) {
29 10
        parent::__construct(self::TYPE);
30
    }
31
32 6
    public function jsonSerialize(): array
33
    {
34 6
        $data = parent::jsonSerialize();
35
36 6
        if ($this->clipPath !== null) {
37 2
            $data['clipPath'] = $this->clipPath;
38
        }
39
40 6
        if ($this->data !== null && !empty($this->data)) {
41 1
            $data['data'] = $this->data;
42
        }
43
44 6
        if ($this->item !== null) {
45 1
            $data['item'] = $this->item;
46
        }
47
48 6
        if ($this->items !== null && !empty($this->items)) {
49 1
            $data['items'] = $this->items;
50
        }
51
52 6
        if ($this->opacity !== null) {
53 3
            $data['opacity'] = $this->opacity;
54
        }
55
56 6
        if ($this->transform !== null) {
57 1
            $data['transform'] = $this->transform;
58
        }
59
60 6
        return $data;
61
    }
62
}
63