LinkBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 51
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 1
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A create() 0 8 1
A getLink() 0 3 1
A setAttributes() 0 5 1
A setRels() 0 5 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