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

GroupRuleValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
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