ImageSource::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Response\Directives\Display;
6
7
use MaxBeckers\AmazonAlexa\Helper\SerializeValueMapper;
8
9
class ImageSource implements \JsonSerializable
10
{
11
    use SerializeValueMapper;
12
13
    public const SIZE_X_SMALL = 'X_SMALL';
14
    public const SIZE_SMALL = 'SMALL';
15
    public const SIZE_MEDIUM = 'MEDIUM';
16
    public const SIZE_LARGE = 'LARGE';
17
    public const SIZE_X_LARGE = 'X_LARGE';
18
19
    public ?string $url = null;
20
    public ?string $size = null;
21
    public ?int $widthPixels = null;
22
    public ?int $heightPixels = null;
23
24 3
    public static function create(string $url, ?string $size = null, ?int $widthPixels = null, ?int $heightPixels = null): self
25
    {
26 3
        $imageSource = new self();
27
28 3
        $imageSource->url = $url;
29 3
        $imageSource->size = $size;
30 3
        $imageSource->widthPixels = $widthPixels;
31 3
        $imageSource->heightPixels = $heightPixels;
32
33 3
        return $imageSource;
34
    }
35
36 2
    public function jsonSerialize(): \ArrayObject
37
    {
38 2
        $data = new \ArrayObject();
39
40 2
        $this->valueToArrayIfSet($data, 'url');
41 2
        $this->valueToArrayIfSet($data, 'size');
42 2
        $this->valueToArrayIfSet($data, 'widthPixels');
43 2
        $this->valueToArrayIfSet($data, 'heightPixels');
44
45 2
        return $data;
46
    }
47
}
48