Completed
Push — master ( aef33f...952551 )
by Gallice
51s queued 10s
created

EntityValue::jsonSerialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
ccs 10
cts 10
cp 1
cc 3
eloc 8
nc 4
nop 0
crap 3
1
<?php
2
3
namespace Tgallice\Wit\Model;
4
5
class EntityValue implements \JsonSerializable
6
{
7
    /**
8
     * @var string
9
     */
10
    private $value;
11
12
    /**
13
     * @var string[]
14
     */
15
    private $expressions;
16
17
    /**
18
     * @var null|string
19
     */
20
    private $metadata;
21
22
    /**
23
     * @param $value
24
     * @param string[] $expressions
25
     * @param null|string $metadata
26
     */
27 5
    public function __construct($value, array $expressions = [], $metadata = null)
28
    {
29 5
        $this->value = $value;
30 5
        $this->expressions = $expressions;
31 5
        $this->metadata = $metadata;
32 5
    }
33
34
    /**
35
     * @return string
36
     */
37 1
    public function getValue()
38
    {
39 1
        return $this->value;
40
    }
41
42
    /**
43
     * @return string[]
44
     */
45 1
    public function getExpressions()
46
    {
47 1
        return $this->expressions;
48
    }
49
50
    /**
51
     * @return null|string
52
     */
53 1
    public function getMetadata()
54
    {
55 1
        return $this->metadata;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61 1
    public function jsonSerialize()
62
    {
63
        $data = [
64 1
            'value' => $this->value,
65 1
        ];
66
67 1
        if (!empty($this->expressions)) {
68 1
            $data['expressions'] = $this->expressions;
69 1
        }
70
71 1
        if (!empty($this->metadata)) {
72 1
            $data['metadata'] = $this->metadata;
73 1
        }
74
75 1
        return $data;
76
    }
77
}
78