Passed
Pull Request — master (#222)
by Dmitriy
12:29
created

GroupRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Closure;
8
use Yiisoft\Validator\Rule\Trait\RuleNameTrait;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_TRAIT, expecting T_STRING or '{' on line 8 at column 27
Loading history...
9
use Yiisoft\Validator\Rule\Trait\HandlerClassNameTrait;
10
use Yiisoft\Validator\RuleInterface;
11
use Yiisoft\Validator\RulesDumper;
12
13
/**
14
 * Validates a single value for a set of custom rules.
15
 */
16
abstract class GroupRule implements RuleInterface
17
{
18
    use HandlerClassNameTrait;
19
    use RuleNameTrait;
20
21
    public function __construct(
22
        public string $message = 'This value is not a valid.',
23
        public bool $skipOnEmpty = false,
24
        public bool $skipOnError = false,
25
        public ?Closure $when = null,
26
    ) {
27
    }
28
29
    /**
30
     * Return custom rules set
31
     */
32
    abstract public function getRuleSet(): array;
33
34 1
    public function getOptions(): array
35
    {
36 1
        $dumper = new RulesDumper();
37
38 1
        return $dumper->asArray($this->getRuleSet(), true);
39
    }
40
}
41