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

One::validateValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10
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