Passed
Push — master ( 00c044...5a9be5 )
by Michael
02:49
created

Definition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 66
c 0
b 0
f 0
ccs 10
cts 16
cp 0.625
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addAttribute() 0 10 2
A getAttributes() 0 4 1
A addRelationship() 0 10 2
A getRelationships() 0 4 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
     * Add attribute
25
     *
26
     * @param  Attribute $attribute
27
     * @throws \LogicException
28
     */
29
    public function addAttribute(Attribute $attribute)
30
    {
31
        $name = $attribute->getName();
32
33
        if (isset($this->attributes[$name])) {
34
            throw new \LogicException(sprintf('Attribute "%s" already defined.', $name));
35
        }
36
37
        $this->attributes[$name] = $attribute;
38
    }
39
40
    /**
41
     * Get attributes
42
     *
43
     * @return Attribute[]
44
     */
45 1
    public function getAttributes(): array
46
    {
47 1
        return $this->attributes;
48
    }
49
50
    /**
51
     * Add relationship
52
     *
53
     * @param  Relationship $relationship
54
     * @throws \LogicException
55
     */
56 4
    public function addRelationship(Relationship $relationship)
57
    {
58 4
        $name = $relationship->getName();
59
60 4
        if (isset($this->relationships[$name])) {
61 1
            throw new \LogicException(sprintf('Relationship "%s" already defined.', $name));
62
        }
63
64 4
        $this->relationships[$name] = $relationship;
65 4
    }
66
67
    /**
68
     * Get relationships
69
     *
70
     * @return Relationship[]
71
     */
72 4
    public function getRelationships(): array
73
    {
74 4
        return $this->relationships;
75
    }
76
}