Passed
Pull Request — master (#138)
by Dmitriy
02:37
created

ValidatorInterfaceProxy::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\RulesProviderInterface;
9
use Yiisoft\Validator\ValidatorInterface;
10
11
final class ValidatorInterfaceProxy implements ValidatorInterface
12
{
13
    public function __construct(
14
        private ValidatorInterface $validator,
15
        private ValidatorCollector $collector,
16
    ) {
17
    }
18
19
    public function validate(mixed $data, iterable $rules = []): Result
20
    {
21
        $result = $this->validator->validate($data, $rules);
22
23
        if ($rules === [] && $data instanceof RulesProviderInterface) {
24
            $rules = (array) $data->getRules();
25
        }
26
27
        $this->collector->collect(
28
            $data,
29
            $rules,
30
            $result,
31
        );
32
33
        return $result;
34
    }
35
}
36