FilteredContainer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation;
6
7
use Everlution\Navigation\Filter\ChainFilter;
8
use Everlution\Navigation\Item\ItemInterface;
9
10
/**
11
 * Class FilteredContainer.
12
 *
13
 * @author Ivan Barlog <[email protected]>
14
 */
15
class FilteredContainer implements ContainerInterface
16
{
17
    /** @var FilteredContainerInterface */
18
    private $container;
19
    /** @var ItemInterface[] */
20
    private $items;
21
22
    public function __construct(FilteredContainerInterface $container)
23
    {
24
        $this->container = $container;
25
    }
26
27
    /**
28
     * @return ItemInterface[]
29
     */
30
    public function getItems(): array
31
    {
32
        if (empty($this->items)) {
33
            $filter = new ChainFilter($this->container->getFilters());
34
            $this->items = $filter->filterItems($this->container)->getItems();
35
        }
36
37
        return $this->items;
38
    }
39
40
    public function get(string $identifier): ItemInterface
41
    {
42
        return $this->items[$identifier];
43
    }
44
}
45