Passed
Pull Request — master (#249)
by Dmitriy
02:52
created

GroupRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10

4 Methods

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