Passed
Push — master ( 39e4c0...d4ca25 )
by Michael
03:36
created

Definition::getLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Mapper\Definition;
5
6
/**
7
 * Mapping Definition
8
 *
9
 * @package Mikemirten\Component\JsonApi\Mapper\Definition
10
 */
11
class Definition
12
{
13
    /**
14
     * @var Attribute[]
15
     */
16
    protected $attributes = [];
17
18
    /**
19
     * @var Relationship[]
20
     */
21
    protected $relationships = [];
22
23
    /**
24
     * @var Link[]
25
     */
26
    protected $links = [];
27
28
    /**
29
     * Add attribute
30
     *
31
     * @param  Attribute $attribute
32
     * @throws \LogicException
33
     */
34
    public function addAttribute(Attribute $attribute)
35
    {
36
        $name = $attribute->getName();
37
38
        if (isset($this->attributes[$name])) {
39
            throw new \LogicException(sprintf('Attribute "%s" already defined.', $name));
40
        }
41
42
        $this->attributes[$name] = $attribute;
43
    }
44
45
    /**
46
     * Get attributes
47
     *
48
     * @return Attribute[]
49
     */
50 1
    public function getAttributes(): array
51
    {
52 1
        return $this->attributes;
53
    }
54
55
    /**
56
     * Add relationship
57
     *
58
     * @param  Relationship $relationship
59
     * @throws \LogicException
60
     */
61 4
    public function addRelationship(Relationship $relationship)
62
    {
63 4
        $name = $relationship->getName();
64
65 4
        if (isset($this->relationships[$name])) {
66 1
            throw new \LogicException(sprintf('Relationship "%s" already defined.', $name));
67
        }
68
69 4
        $this->relationships[$name] = $relationship;
70 4
    }
71
72
    /**
73
     * Get relationships
74
     *
75
     * @return Relationship[]
76
     */
77 4
    public function getRelationships(): array
78
    {
79 4
        return $this->relationships;
80
    }
81
82
    /**
83
     * Add link
84
     *
85
     * @param Link $link
86
     */
87 2
    public function addLink(Link $link)
88
    {
89 2
        $name = $link->getName();
90
91 2
        if (isset($this->links[$name])) {
92 1
            throw new \LogicException(sprintf('Link "%s" already defined.', $name));
93
        }
94
95 2
        $this->links[$name] = $link;
96 2
    }
97
98
    /**
99
     * Get links
100
     *
101
     * @return Link[]
102
     */
103 1
    public function getLinks(): array
104
    {
105 1
        return $this->links;
106
    }
107
}