Passed
Pull Request — master (#6)
by
unknown
02:09
created

FilteredContainer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

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