Link::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

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