Passed
Pull Request — master (#412)
by
unknown
17:58 queued 15:20
created

NotNullHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Support\Rule\NotNullRule;
6
7
use Yiisoft\Validator\Exception\UnexpectedRuleException;
8
use Yiisoft\Validator\Result;
9
use Yiisoft\Validator\RuleHandlerInterface;
10
use Yiisoft\Validator\ValidationContext;
11
12
final class NotNullHandler implements RuleHandlerInterface
13
{
14
    public function validate(mixed $value, object $rule, ValidationContext $context): Result
15
    {
16
        if (!$rule instanceof NotNull) {
17
            throw new UnexpectedRuleException(NotNull::class, $rule);
18
        }
19
20
        $result = new Result();
21
22
        if ($value === null) {
23
            $result->addError('Values must not be null.');
24
        }
25
26
        return $result;
27
    }
28
}
29