Passed
Pull Request — master (#249)
by Alexander
05:48 queued 02:51
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\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