ImageSource::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 3
    public function __construct(
20
        public ?string $url = null,
21
        public ?string $size = null,
22
        public ?int $widthPixels = null,
23
        public ?int $heightPixels = null
24
    ) {
25 3
    }
26
27 3
    public static function create(string $url, ?string $size = null, ?int $widthPixels = null, ?int $heightPixels = null): self
28
    {
29 3
        return new self($url, $size, $widthPixels, $heightPixels);
30
    }
31
32 2
    public function jsonSerialize(): \ArrayObject
33
    {
34 2
        $data = new \ArrayObject();
35
36 2
        $this->valueToArrayIfSet($data, 'url');
37 2
        $this->valueToArrayIfSet($data, 'size');
38 2
        $this->valueToArrayIfSet($data, 'widthPixels');
39 2
        $this->valueToArrayIfSet($data, 'heightPixels');
40
41 2
        return $data;
42
    }
43
}
44