Passed
Pull Request — master (#222)
by Dmitriy
02:26
created

Subset   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 33
ccs 7
cts 8
cp 0.875
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getOptions() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Subset;
6
7
use Attribute;
8
use Closure;
9
use Yiisoft\Validator\Rule\RuleNameTrait;
10
use Yiisoft\Validator\Rule\HandlerClassNameTrait;
11
use Yiisoft\Validator\RuleInterface;
12
13
#[Attribute(Attribute::TARGET_PROPERTY)]
14
final class Subset implements RuleInterface
15
{
16
    use HandlerClassNameTrait;
17
    use RuleNameTrait;
18
19
    public function __construct(
20
        public iterable $values,
21
        /**
22
         * @var bool whether the comparison is strict (both type and value must be the same)
23
         */
24
        public bool $strict = false,
25
        public string $iterableMessage = 'Value must be iterable.',
26
        public string $subsetMessage = 'Values must be ones of {values}.',
27
        public bool $skipOnEmpty = false,
28
        public bool $skipOnError = false,
29
        public ?Closure $when = null,
30
    ) {
31
    }
32
33 1
    public function getOptions(): array
34
    {
35
        return [
36 1
            'values' => $this->values,
37 1
            'strict' => $this->strict,
38
            'iterableMessage' => [
39 1
                'message' => $this->iterableMessage,
40
            ],
41
            'subsetMessage' => [
42 1
                'message' => $this->subsetMessage,
43
            ],
44 1
            'skipOnEmpty' => $this->skipOnEmpty,
45 1
            'skipOnError' => $this->skipOnError,
46
        ];
47
    }
48
}
49