Passed
Pull Request — master (#249)
by Alexander
05:48 queued 02:51
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 Closure;
8
use Yiisoft\Validator\SerializableRuleInterface;
9
use Yiisoft\Validator\BeforeValidationInterface;
10
use Yiisoft\Validator\Rule\Trait\BeforeValidationTrait;
11
use Yiisoft\Validator\Rule\Trait\RuleNameTrait;
12
use Yiisoft\Validator\RulesDumper;
13
use Yiisoft\Validator\ValidationContext;
14
15
/**
16
 * Validates a single value for a set of custom rules.
17
 */
18
abstract class GroupRule implements SerializableRuleInterface, BeforeValidationInterface
19
{
20
    use BeforeValidationTrait;
21
    use RuleNameTrait;
22
23 2
    public function __construct(
24
        private string $message = 'This value is not a valid.',
25
        private bool $skipOnEmpty = false,
26
        private bool $skipOnError = false,
27
        /**
28
         * @var Closure(mixed, ValidationContext):bool|null
29
         */
30
        private ?Closure $when = null,
31
    ) {
32
    }
33
34
    /**
35
     * @return string
36
     */
37 4
    public function getMessage(): string
38
    {
39 4
        return $this->message;
40
    }
41
42
    /**
43
     * Return custom rules set
44
     */
45
    abstract public function getRuleSet(): array;
46
47 1
    public function getOptions(): array
48
    {
49 1
        return (new RulesDumper())->asArray($this->getRuleSet());
50
    }
51
52 1
    public function getHandlerClassName(): string
53
    {
54 1
        return GroupRuleHandler::class;
55
    }
56
}
57