Passed
Push — master ( 19a485...913337 )
by Michael
02:43
created

LinksContainer::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
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
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\Behaviour;
5
6
use Mikemirten\Component\JsonApi\Mapper\Definition\Link;
7
8
/**
9
 * An implementation of links-container behaviour
10
 *
11
 * @package Mikemirten\Component\JsonApi\Mapper\Definition\Behaviour
12
 */
13
trait LinksContainer
14
{
15
    /**
16
     * Collection of links
17
     *
18
     * @var Link[]
19
     */
20
    protected $links = [];
21
22
    /**
23
     * Set link
24
     *
25
     * @param Link $link
26
     */
27 7
    public function addLink(Link $link)
28
    {
29 7
        $name = $link->getName();
30
31 7
        if (isset($this->links[$name])) {
32 1
            throw new \LogicException(sprintf('A link name by "%s" is already exists.', $name));
33
        }
34
35 7
        $this->links[$name] = $link;
36 7
    }
37
38
    /**
39
     * Get links
40
     * [name => Link]
41
     *
42
     * @return Link[]
43
     */
44 5
    public function getLinks(): array
45
    {
46 5
        return $this->links;
47
    }
48
}