Completed
Push — master ( f2d77a...6972d7 )
by Jasper
11s
created

Jsonapi   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getVersion() 0 3 1
A toArray() 0 13 3
1
<?php
2
3
namespace Swis\JsonApi\Client;
4
5
use Swis\JsonApi\Client\Traits\HasMeta;
6
7
class Jsonapi
8
{
9
    use HasMeta;
10
11
    /**
12
     * @var string|null
13
     */
14
    protected $version;
15
16
    /**
17
     * @param string|null                    $version
18
     * @param \Swis\JsonApi\Client\Meta|null $meta
19
     */
20
    public function __construct(string $version = null, Meta $meta = null)
21
    {
22
        $this->version = $version;
23
        $this->meta = $meta;
24
    }
25
26
    /**
27
     * @return string|null
28
     */
29
    public function getVersion()
30
    {
31
        return $this->version;
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function toArray(): array
38
    {
39
        $array = [];
40
41
        if ($this->getVersion() !== null) {
42
            $array['version'] = $this->getVersion();
43
        }
44
45
        if ($this->getMeta() !== null) {
46
            $array['meta'] = $this->getMeta()->toArray();
47
        }
48
49
        return $array;
50
    }
51
}
52