Passed
Push — master ( 13b184...82bbaa )
by Alexander
07:06
created

GroupRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 21
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Yiisoft\Validator\HasValidationErrorMessage;
8
use Yiisoft\Validator\Rule;
9
use Yiisoft\Validator\Result;
10
use Yiisoft\Validator\DataSetInterface;
11
use Yiisoft\Validator\Rules;
12
13
/**
14
 * GroupRule validates a single value for a set of custom rules
15
 */
16
abstract class GroupRule extends Rule
17
{
18
    use HasValidationErrorMessage;
19
20
    protected string $message = 'This value is not a valid.';
21
22 3
    protected function validateValue($value, DataSetInterface $dataSet = null): Result
23
    {
24 3
        $result = new Result();
25 3
        if (!$this->getRules()->validate($value, $dataSet)->isValid()) {
26 3
            $result->addError($this->translateMessage($this->message));
27
        }
28
29 3
        return $result;
30
    }
31
32
    /**
33
     * Return custom rules set
34
     * @return Rules
35
     */
36
    abstract protected function getRules(): Rules;
37
}
38