Passed
Push — master ( e26598...4977ef )
by Jin
02:11
created

One   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 8
cp 0.875
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 10 2
A rule() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace jin2chen\YiiValidator\Rule;
6
7
use InvalidArgumentException;
8
use jin2chen\YiiValidator\NestRule;
9
use Yiisoft\Validator\Result;
10
use Yiisoft\Validator\ValidationContext;
11
12
/**
13
 * @method One withRules(iterable $rules)
14
 */
15
final class One extends NestRule
16
{
17 2
    public static function rule(): One
18
    {
19 2
        return new One();
20
    }
21
22 2
    protected function validateValue($value, ValidationContext $context = null): Result
23
    {
24 2
        if (!$context) {
25
            throw new InvalidArgumentException('Context must be set.');
26
        }
27
28 2
        $results = $this->getValidator()->validate($value, $this->getRules());
29 2
        $this->addResultSet($results, $context->getAttribute() ?? '');
30
31 2
        return new Result();
32
    }
33
}
34