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

ValidatorInterfaceProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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\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