DataContainerFilterChain::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.9332
cc 2
nc 1
nop 1
crap 2
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