Total Complexity | 7 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Coverage | 88.24% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Jsonapi implements Arrayable, Jsonable, JsonSerializable |
||
11 | { |
||
12 | use HasMeta; |
||
13 | |||
14 | /** |
||
15 | * @var string|null |
||
16 | */ |
||
17 | protected $version; |
||
18 | |||
19 | /** |
||
20 | * @param string|null $version |
||
21 | * @param \Swis\JsonApi\Client\Meta|null $meta |
||
22 | */ |
||
23 | 45 | public function __construct(string $version = null, Meta $meta = null) |
|
27 | 45 | } |
|
28 | |||
29 | /** |
||
30 | * @return string|null |
||
31 | */ |
||
32 | 27 | public function getVersion() |
|
33 | { |
||
34 | 27 | return $this->version; |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | 18 | public function toArray(): array |
|
43 | { |
||
44 | 18 | $array = []; |
|
45 | |||
46 | 18 | if ($this->getVersion() !== null) { |
|
47 | 9 | $array['version'] = $this->getVersion(); |
|
48 | } |
||
49 | |||
50 | 18 | if ($this->getMeta() !== null) { |
|
51 | 9 | $array['meta'] = $this->getMeta()->toArray(); |
|
52 | } |
||
53 | |||
54 | 18 | return $array; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | * |
||
60 | * @param int $options |
||
61 | * |
||
62 | * @return false|string |
||
63 | */ |
||
64 | public function toJson($options = 0) |
||
65 | { |
||
66 | return json_encode($this->jsonSerialize(), $options); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | * |
||
72 | * @return object |
||
73 | */ |
||
74 | 9 | public function jsonSerialize() |
|
77 | } |
||
78 | } |
||
79 |