Passed
Pull Request — master (#11)
by
unknown
02:23
created

MutableContainer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 7
dl 0
loc 31
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A reset() 0 3 1
A getItems() 0 3 1
A get() 0 3 1
A getIdentifier() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation;
6
7
use Everlution\Navigation\Item\IdentifiableInterface;
8
use Everlution\Navigation\Item\ItemInterface;
9
10
/**
11
 * Class MutableContainer.
12
 *
13
 * @author Ivan Barlog <[email protected]>
14
 */
15
abstract class MutableContainer implements MutableContainerInterface
16
{
17
    /** @var ItemInterface[] */
18
    private $items = [];
19
20
    public function add(ItemInterface $item): void
21
    {
22
        $this->items[self::getIdentifier($item)] = $item;
23
    }
24
25
    /**
26
     * @return \Everlution\Navigation\Item\ItemInterface[]
27
     */
28
    public function getItems(): array
29
    {
30
        return $this->items;
31
    }
32
33
    public function get(string $identifier): ItemInterface
34
    {
35
        return $this->items[$identifier];
36
    }
37
38
    public function reset(): void
39
    {
40
        $this->items = [];
41
    }
42
43
    public static function getIdentifier(ItemInterface $item): string
44
    {
45
        return $item instanceof IdentifiableInterface ? $item->getIdentifier() : get_class($item);
46
    }
47
48
}
49