Passed
Pull Request — master (#222)
by Dmitriy
02:50
created

GroupRuleHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\ValidationContext;
9
use Yiisoft\Validator\Exception\UnexpectedRuleException;
10
11
/**
12
 * Validates a single value for a set of custom rules.
13
 */
14
class GroupRuleHandler implements RuleHandlerInterface
15
{
16 6
    public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result
17
    {
18 6
        if (!$rule instanceof GroupRule) {
19 1
            throw new UnexpectedRuleException(GroupRule::class, $rule);
20
        }
21
22 5
        $result = new Result();
23 5
        if (!$context->getValidator()->validate($value, $rule->getRuleSet())->isValid()) {
0 ignored issues
show
Bug introduced by
The method getValidator() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        if (!$context->/** @scrutinizer ignore-call */ getValidator()->validate($value, $rule->getRuleSet())->isValid()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24 4
            $result->addError($rule->message);
25
        }
26
27 5
        return $result;
28
    }
29
}
30