Passed
Branch master (6982d9)
by Ivan
02:35
created

FilteredContainer::getItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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 (!$this->items) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->items of type Everlution\Navigation\Item\ItemInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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 $name): ItemInterface
41
    {
42
        return $this->items[$name];
43
    }
44
}
45