Passed
Pull Request — master (#222)
by Dmitriy
12:29
created

Subset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 45
ccs 10
cts 18
cp 0.5556
rs 10
c 2
b 1
f 0
wmc 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Attribute;
8
use Closure;
9
use Yiisoft\Validator\Rule\Trait\RuleNameTrait;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_TRAIT, expecting T_STRING or '{' on line 9 at column 27
Loading history...
10
use Yiisoft\Validator\Rule\Trait\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