VectorGraphicComponent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 6
dl 0
loc 9
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ImageAlign;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Scale;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
11
12
class VectorGraphicComponent extends TouchableComponent implements \JsonSerializable
13
{
14
    public const TYPE = APLComponentType::VECTOR_GRAPHIC;
15
16
    /**
17
     * @param ImageAlign|null $align Alignment of the vector graphic within the component
18
     * @param AbstractStandardCommand[]|null $onFail Commands to run when the source fails to load
19
     * @param AbstractStandardCommand[]|null $onLoad Commands to run after the source loads
20
     * @param array|null $parameters Optional map of parameters to pass to the vector graphic
21
     * @param Scale|null $scale How the vector graphic scales up or down within the component
22
     * @param string|null $source The URL or direct reference to a vector graphic
23
     */
24 10
    public function __construct(
25
        public ?ImageAlign $align = null,
26
        public ?array $onFail = null,
27
        public ?array $onLoad = null,
28
        public ?array $parameters = null,
29
        public ?Scale $scale = null,
30
        public ?string $source = null,
31
    ) {
32 10
        parent::__construct(self::TYPE);
33
    }
34
35 6
    public function jsonSerialize(): array
36
    {
37 6
        $data = parent::jsonSerialize();
38
39 6
        if ($this->align !== null) {
40 3
            $data['align'] = $this->align->value;
41
        }
42
43 6
        if ($this->onFail !== null && !empty($this->onFail)) {
44 1
            $data['onFail'] = $this->onFail;
45
        }
46
47 6
        if ($this->onLoad !== null && !empty($this->onLoad)) {
48 1
            $data['onLoad'] = $this->onLoad;
49
        }
50
51 6
        if ($this->parameters !== null && !empty($this->parameters)) {
52 1
            $data['parameters'] = $this->parameters;
53
        }
54
55 6
        if ($this->scale !== null) {
56 2
            $data['scale'] = $this->scale->value;
57
        }
58
59 6
        if ($this->source !== null) {
60 2
            $data['source'] = $this->source;
61
        }
62
63 6
        return $data;
64
    }
65
}
66