Passed
Pull Request — master (#245)
by Rustam
12:07
created

GroupRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 33
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMessage() 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\ParametrizedRuleInterface;
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 ParametrizedRuleInterface, BeforeValidationInterface
20
{
21
    use BeforeValidationTrait;
22
    use HandlerClassNameTrait;
23
    use RuleNameTrait;
24
25 1
    public function __construct(
26
        private string $message = 'This value is not a valid.',
27
        private bool $skipOnEmpty = false,
28
        private bool $skipOnError = false,
29
        /**
30
         * @var Closure(mixed, ValidationContext):bool|null
31
         */
32
        private ?Closure $when = null,
33
    ) {
34
    }
35
36
    /**
37
     * @return string
38
     */
39 4
    public function getMessage(): string
40
    {
41 4
        return $this->message;
42
    }
43
44
    /**
45
     * Return custom rules set
46
     */
47
    abstract public function getRuleSet(): array;
48
49 1
    public function getOptions(): array
50
    {
51 1
        return (new RulesDumper())->asArray($this->getRuleSet());
52
    }
53
}
54