ValidationFilterManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 31
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 10 3
A add() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rs\XmlFilter\Filter\Manager;
6
7
use Rs\XmlFilter\Document\Element;
8
use Rs\XmlFilter\Filter\Filter;
9
10
class ValidationFilterManager implements FilterManager
11
{
12
    /**
13
     * @var FilterManager
14
     */
15
    protected $filterManager;
16
17 45
    public function __construct(FilterManager $filterManager)
18
    {
19 45
        $this->filterManager = $filterManager;
20 45
    }
21
22 28
    public function filter(Element $element, string $filter, array $options)
23
    {
24 28
        $result = $this->filterManager->filter($element, $filter, $options);
25
26 28
        if (isset($options['validate']) && is_callable($options['validate'])) {
27
            $options['validate']($result);
28
        }
29
30 28
        return $result;
31
    }
32
33
    /**
34
     * @param Filter|callable $filter
35
     */
36 2
    public function add(string $name, $filter)
37
    {
38 2
        $this->filterManager->add($name, $filter);
39 2
    }
40
}
41