ImageSource   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
eloc 23
c 2
b 1
f 0
dl 0
loc 63
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 10 1
A create() 0 10 1
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Response\Directives\Display;
4
5
use MaxBeckers\AmazonAlexa\Helper\SerializeValueMapper;
6
7
/**
8
 * @author Maximilian Beckers <[email protected]>
9
 */
10
class ImageSource implements \JsonSerializable
11
{
12
    use SerializeValueMapper;
13
14
    const SIZE_X_SMALL = 'X_SMALL';
15
    const SIZE_SMALL   = 'SMALL';
16
    const SIZE_MEDIUM  = 'MEDIUM';
17
    const SIZE_LARGE   = 'LARGE';
18
    const SIZE_X_LARGE = 'X_LARGE';
19
20
    /**
21
     * @var string|null
22
     */
23
    public $url;
24
25
    /**
26
     * @var string|null
27
     */
28
    public $size;
29
30
    /**
31
     * @var int|null
32
     */
33
    public $widthPixels;
34
35
    /**
36
     * @var int|null
37
     */
38
    public $heightPixels;
39
40
    /**
41
     * @param string      $url
42
     * @param string|null $size
43
     * @param int|null    $widthPixels
44
     * @param int|null    $heightPixels
45
     *
46
     * @return ImageSource
47
     */
48 3
    public static function create($url, $size = null, $widthPixels = null, $heightPixels = null): self
49
    {
50 3
        $imageSource = new self();
51
52 3
        $imageSource->url          = $url;
53 3
        $imageSource->size         = $size;
54 3
        $imageSource->widthPixels  = $widthPixels;
55 3
        $imageSource->heightPixels = $heightPixels;
56
57 3
        return $imageSource;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63 2
    public function jsonSerialize()
64
    {
65 2
        $data = new \ArrayObject();
66
67 2
        $this->valueToArrayIfSet($data, 'url');
68 2
        $this->valueToArrayIfSet($data, 'size');
69 2
        $this->valueToArrayIfSet($data, 'widthPixels');
70 2
        $this->valueToArrayIfSet($data, 'heightPixels');
71
72 2
        return $data;
73
    }
74
}
75