Passed
Push — master ( 749ee4...dbf6d0 )
by Maximilian
01:14
created

TextContent::jsonSerialize()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 15
rs 10
cc 4
nc 8
nop 0
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Response\Directives\Display;
4
5
/**
6
 * @author Maximilian Beckers <[email protected]>
7
 */
8
class TextContent implements \JsonSerializable
9
{
10
    /**
11
     * @var Text|null
12
     */
13
    public $primaryText;
14
15
    /**
16
     * @var Text|null
17
     */
18
    public $secondaryText;
19
20
    /**
21
     * @var Text|null
22
     */
23
    public $tertiaryText;
24
25
    /**
26
     * @param Text|null $primaryText
27
     * @param Text|null $secondaryText
28
     * @param Text|null $tertiaryText
29
     *
30
     * @return TextContent
31
     */
32
    public static function create($primaryText = null, $secondaryText = null, $tertiaryText = null): self
33
    {
34
        $textContent = new self();
35
36
        $textContent->primaryText   = $primaryText;
37
        $textContent->secondaryText = $secondaryText;
38
        $textContent->tertiaryText  = $tertiaryText;
39
40
        return $textContent;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function jsonSerialize()
47
    {
48
        $data = new \ArrayObject();
49
50
        if (null !== $this->primaryText) {
51
            $data['primaryText'] = $this->primaryText;
52
        }
53
        if (null !== $this->secondaryText) {
54
            $data['secondaryText'] = $this->secondaryText;
55
        }
56
        if (null !== $this->tertiaryText) {
57
            $data['tertiaryText'] = $this->tertiaryText;
58
        }
59
60
        return $data;
61
    }
62
}
63