Passed
Push — master ( e05223...e18482 )
by
unknown
06:52 queued 03:38
created

RuleWithBuiltInHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 16
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

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