Passed
Pull Request — master (#132)
by Dmitriy
05:52 queued 02:50
created

ValidatorInterfaceProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
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