Passed
Pull Request — master (#80)
by
unknown
13:49 queued 11:12
created

TypeValue::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MaxBeckers\AmazonAlexa\Response\Directives\Dialog\Entity;
4
5
class TypeValue implements \JsonSerializable
6
{
7
    /**
8
     * @var string
9
     */
10
    public $id;
11
12
    /**
13
     * @var string
14
     */
15
    public $value;
16
17
    /**
18
     * @var array
19
     */
20
    public $synonyms;
21
22
    /**
23
     * @param string $id
24
     * @param string $value
25
     * @param array  $synonyms
26
     *
27
     * @return TypeValue
28
     */
29
    public static function create(string $id, string $value, array $synonyms = []): self
30
    {
31
        $typeValue = new self();
32
33
        $typeValue->id       = $id;
34
        $typeValue->value    = $value;
35
        $typeValue->synonyms = $synonyms;
36
37
        return $typeValue;
38
    }
39
40
    /**
41
     * Specify data which should be serialized to JSON.
42
     *
43
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
44
     *
45
     * @return mixed data which can be serialized by <b>json_encode</b>,
46
     *               which is a value of any type other than a resource
47
     *
48
     * @since 5.4.0
49
     */
50
    public function jsonSerialize()
51
    {
52
        return [
53
            'id'   => $this->id,
54
            'name' => [
55
                'value'    => $this->value,
56
                'synonyms' => $this->synonyms,
57
            ],
58
        ];
59
    }
60
}
61