Passed
Pull Request — master (#222)
by Alexander
04:47 queued 02:23
created

GroupRuleValidator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\GroupRule;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\Rule\RuleValidatorInterface;
9
use Yiisoft\Validator\ValidationContext;
10
use Yiisoft\Validator\ValidatorInterface;
11
12
/**
13
 * Validates a single value for a set of custom rules.
14
 */
15
class GroupRuleValidator implements RuleValidatorInterface
16
{
17 5
    public function validate(mixed $value, object $rule, ValidatorInterface $validator, ?ValidationContext $context = null): Result
18
    {
19 5
        $result = new Result();
20 5
        if (!$validator->validate($value, $rule->getRuleSet())->isValid()) {
21 4
            $result->addError($rule->message);
22
        }
23
24 5
        return $result;
25
    }
26
}
27