Metadata::jsonSerialize()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.6111
c 1
b 0
f 0
cc 5
nc 16
nop 0
crap 5
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Response\Directives\AudioPlayer;
4
5
use MaxBeckers\AmazonAlexa\Response\Directives\Display\Image;
6
7
/**
8
 * @author Maximilian Beckers <[email protected]>
9
 */
10
class Metadata implements \JsonSerializable
11
{
12
    /**
13
     * @var string|null
14
     */
15
    public $title;
16
17
    /**
18
     * @var string|null
19
     */
20
    public $subtitle;
21
22
    /**
23
     * @var Image|null
24
     */
25
    public $art;
26
27
    /**
28
     * @var Image|null
29
     */
30
    public $backgroundImage;
31
32
    /**
33
     * @param string|null $title
34
     * @param string|null $subtitle
35
     * @param Image|null  $art
36
     * @param Image|null  $backgroundImage
37
     *
38
     * @return Metadata
39
     */
40 1
    public static function create(string $title = null, string $subtitle = null, Image $art = null, Image $backgroundImage = null): self
41
    {
42 1
        $metadata = new self();
43
44 1
        $metadata->title           = $title;
45 1
        $metadata->subtitle        = $subtitle;
46 1
        $metadata->art             = $art;
47 1
        $metadata->backgroundImage = $backgroundImage;
48
49 1
        return $metadata;
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55 1
    public function jsonSerialize()
56
    {
57 1
        $data = [];
58
59 1
        if (null !== $this->title) {
60 1
            $data['title'] = $this->title;
61
        }
62 1
        if (null !== $this->subtitle) {
63 1
            $data['subtitle'] = $this->subtitle;
64
        }
65 1
        if (null !== $this->art) {
66 1
            $data['art'] = $this->art;
67
        }
68 1
        if (null !== $this->backgroundImage) {
69 1
            $data['backgroundImage'] = $this->backgroundImage;
70
        }
71
72 1
        return $data;
73
    }
74
}
75