DataContainerFilterChain   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * Copyright MediaCT. All rights reserved.
5
 * https://www.mediact.nl
6
 */
7
8
namespace Mediact\DataContainer;
9
10
class DataContainerFilterChain implements DataContainerFilterInterface
11
{
12
    /** @var DataContainerFilterInterface[] */
13
    private $filters;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param DataContainerFilterInterface[] ...$filters
19
     */
20 9
    public function __construct(DataContainerFilterInterface ...$filters)
21
    {
22 9
        $this->filters = $filters;
23 9
    }
24
25
    /**
26
     * Filter the given container.
27
     *
28
     * @param DataContainerInterface $container
29
     *
30
     * @return bool
31
     */
32 9
    public function __invoke(DataContainerInterface $container): bool
33
    {
34 9
        return array_reduce(
35 9
            $this->filters,
36
            function (
37
                bool $carry,
38
                DataContainerFilterInterface $filter
39
            ) use (
40 8
                $container
41
            ): bool {
42 8
                return $carry && $filter($container);
43 9
            },
44 9
            true
45
        );
46
    }
47
}
48