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