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

One::rule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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