RemoveNotSupportedRoleFilter   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterItems() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation\Filter;
6
7
use Everlution\Navigation\Item\HasSupportedRolesInterface;
8
use Everlution\Navigation\Item\ItemInterface;
9
use Everlution\Navigation\MutableContainerInterface;
10
11
/**
12
 * Class FilterByRoleKeepNotSupported.
13
 *
14
 * @author Ivan Barlog <[email protected]>
15
 */
16
class RemoveNotSupportedRoleFilter implements NavigationFilterInterface
17
{
18
    public function filterItems(MutableContainerInterface $container): MutableContainerInterface
19
    {
20
        $filtered = clone $container;
21
        $filtered->reset();
22
23
        array_map(
24
            [$filtered, 'add'],
25
            array_filter(
26
                $container->getItems(),
27
                function (ItemInterface $item) {
28
                    return $item instanceof HasSupportedRolesInterface;
29
                }
30
            )
31
        );
32
33
        return $filtered;
34
    }
35
}
36