LinkBuilder::setRels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Link;
6
7
use Psr\Link\LinkInterface;
8
9
final class LinkBuilder implements LinkBuilderInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $href;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $rels;
20
21
    /**
22
     * @var array
23
     */
24
    private $attributes;
25
26 2
    private function __construct()
27
    {
28 2
    }
29
30
    public static function create(string $href): LinkBuilderInterface
31
    {
32
        $self = new self();
33
        $self->href = $href;
34
        $self->rels = [];
35 2
        $self->attributes = [];
36
37 2
        return $self;
38 2
    }
39 2
40 2
    /**
41
     * @param string[] $rels
42 2
     */
43
    public function setRels(array $rels): LinkBuilderInterface
44
    {
45
        $this->rels = $rels;
46
47
        return $this;
48
    }
49
50 1
    public function setAttributes(array $attributes): LinkBuilderInterface
51
    {
52 1
        $this->attributes = $attributes;
53
54 1
        return $this;
55
    }
56
57
    public function getLink(): LinkInterface
58
    {
59
        return new Link($this->href, $this->rels, $this->attributes);
60
    }
61
}
62