Passed
Pull Request — master (#4)
by Jan-Marten
06:24
created

DataContainerFilterChain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

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