Passed
Push — master ( 54fc89...e67e2c )
by Maximilian
01:13
created

Metadata::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
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
    public static function create(string $title = null, string $subtitle = null, Image $art = null, Image $backgroundImage = null): self
41
    {
42
        $metadata = new self();
43
44
        $metadata->title           = $title;
45
        $metadata->subtitle        = $subtitle;
46
        $metadata->art             = $art;
47
        $metadata->backgroundImage = $backgroundImage;
48
49
        return $metadata;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function jsonSerialize()
56
    {
57
        $data = [];
58
59
        if (null !== $this->title) {
60
            $data['title'] = $this->title;
61
        }
62
        if (null !== $this->subtitle) {
63
            $data['subtitle'] = $this->subtitle;
64
        }
65
        if (null !== $this->art) {
66
            $data['art'] = $this->art;
67
        }
68
        if (null !== $this->backgroundImage) {
69
            $data['backgroundImage'] = $this->backgroundImage;
70
        }
71
72
        return $data;
73
    }
74
}
75