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

Subset::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 1
rs 9.9666
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