Passed
Push — master ( c03911...dc22ae )
by Mike
01:48
created

FieldHandlerPlugin::handleArrayConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Validator\Communication\Plugin\FieldHandler;
5
6
7
use Xervice\ArrayHandler\Dependency\FieldHandlerPluginInterface;
8
use Xervice\Core\Plugin\AbstractBusinessPlugin;
9
10
class FieldHandlerPlugin extends AbstractBusinessPlugin implements FieldHandlerPluginInterface
11
{
12
    /**
13
     * @var \Xervice\Validator\Business\Dependency\ValidatorTypePluginInterface[]
14
     */
15
    protected $validatorTypes;
16
17
    /**
18
     * FieldHandlerPlugin constructor.
19
     *
20
     * @param \Xervice\Validator\Business\Dependency\ValidatorTypePluginInterface[] $validatorTypes
21
     */
22 5
    public function __construct(array $validatorTypes)
23
    {
24 5
        $this->validatorTypes = $validatorTypes;
25 5
    }
26
27
    /**
28
     * @param array $data
29
     * @param mixed $fieldName
30
     * @param string $config
31
     *
32
     * @return array
33
     */
34 5
    public function handleSimpleConfig(array $data, $fieldName, string $config): array
35
    {
36 5
        foreach ($this->validatorTypes as $validatorType) {
37 5
            if ($validatorType->isResponsible($config)) {
38 5
                $validatorType->validate($data, $fieldName, $config);
39
            }
40
        }
41
42 5
        return $data;
43
    }
44
45
    /**
46
     * @param array $data
47
     * @param mixed $fieldName
48
     * @param array $config
49
     *
50
     * @return array
51
     */
52 4
    public function handleNestedConfig(array $data, $fieldName, array $config): array
53
    {
54 4
        foreach ($this->validatorTypes as $validatorType) {
55 4
            if ($validatorType->isResponsible($config)) {
56 4
                $validatorType->validate($data, $fieldName, $config);
57
            }
58
        }
59
60 4
        return $data;
61
    }
62
63
    /**
64
     * @param array $data
65
     * @param array $config
66
     *
67
     * @return array
68
     */
69
    public function handleArrayConfig(array $data, array $config): array
70
    {
71
        return $data;
72
    }
73
74
75
    /**
76
     * @param array $data
77
     * @param mixed $fieldName
78
     * @param callable $config
79
     *
80
     * @return array
81
     */
82 3
    public function handleCallableConfig(array $data, $fieldName, callable $config): array
83
    {
84 3
        foreach ($this->validatorTypes as $validatorType) {
85 3
            if ($validatorType->isResponsible($config)) {
86 3
                $validatorType->validate($data, $fieldName, $config);
87
            }
88
        }
89
90 2
        return $data;
91
    }
92
}