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

MutableContainer::getIdentifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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