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

Link::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Swis\JsonApi\Client;
4
5
use Swis\JsonApi\Client\Traits\HasMeta;
6
7
class Link
8
{
9
    use HasMeta;
10
11
    /**
12
     * @var string
13
     */
14
    protected $href;
15
16
    /**
17
     * @param string                         $href
18
     * @param \Swis\JsonApi\Client\Meta|null $meta
19
     */
20
    public function __construct(string $href, Meta $meta = null)
21
    {
22
        $this->href = $href;
23
        $this->meta = $meta;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getHref(): string
30
    {
31
        return $this->href;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @return array
38
     */
39
    public function toArray()
40
    {
41
        $array = [
42
            'href' => $this->getHref(),
43
        ];
44
45
        if ($this->getMeta() !== null) {
46
            $array['meta'] = $this->getMeta()->toArray();
47
        }
48
49
        return $array;
50
    }
51
}
52