Completed
Push — master ( 97e94f...81eace )
by Dmitriy
15s queued 13s
created

ValidatorInterfaceProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Debug;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\RulesProviderInterface;
9
use Yiisoft\Validator\ValidationContext;
10
use Yiisoft\Validator\ValidatorInterface;
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(
21
        mixed $data,
22
        callable|iterable|object|string|null $rules = null,
23
        ?ValidationContext $context = null
24
    ): Result {
25
        $result = $this->validator->validate($data, $rules, $context);
26
27
        if ($rules === null && $data instanceof RulesProviderInterface) {
28
            $rules = (array) $data->getRules();
29
        }
30
31
        $this->collector->collect(
32
            $data,
33
            $result,
34
            $rules,
35
        );
36
37
        return $result;
38
    }
39
}
40