Passed
Push — master ( 097d20...39b40c )
by Alexander
01:30
created

GroupRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 8 2
A getOptions() 0 3 1
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 3
    public function getOptions(): array
39
    {
40 3
        return $this->getRules()->asArray();
41
    }
42
}
43