Passed
Push — master ( 1b3b54...96eb95 )
by Dmitriy
03:22 queued 11s
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\Proxy;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\RulesProviderInterface;
9
use Yiisoft\Validator\ValidatorInterface;
10
use Yiisoft\Yii\Debug\Collector\ValidatorCollector;
11
12
final class ValidatorInterfaceProxy implements ValidatorInterface
13
{
14
    public function __construct(
15
        private ValidatorInterface $validator,
16
        private ValidatorCollector $collector,
17
    ) {
18
    }
19
20
    public function validate(mixed $data, iterable $rules = []): Result
21
    {
22
        $result = $this->validator->validate($data, $rules);
23
24
        if ($rules === [] && $data instanceof RulesProviderInterface) {
25
            $rules = (array) $data->getRules();
26
        }
27
28
        $this->collector->collect(
29
            $data,
30
            $rules,
31
            $result,
32
        );
33
34
        return $result;
35
    }
36
}
37