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

GroupRule::getOptions()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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