Passed
Push — master ( 96eb95...5f23c4 )
by Dmitriy
02:55 queued 24s
created

ValidatorInterfaceProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 23
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 15 3
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