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

Required   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5
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
/**
14
 * Validates that the specified value is neither null nor empty.
15
 */
16
#[Attribute(Attribute::TARGET_PROPERTY)]
17
final class Required implements RuleInterface
18
{
19
    use HandlerClassNameTrait;
20
    use RuleNameTrait;
21
22 12
    public function __construct(
23
        public string $message = 'Value cannot be blank.',
24
        public bool $skipOnEmpty = false,
25
        public bool $skipOnError = false,
26
        public ?Closure $when = null,
27
    ) {
28
    }
29
30 2
    public function getOptions(): array
31
    {
32
        return [
33
            'message' => [
34 2
                'message' => $this->message,
35
            ],
36 2
            'skipOnEmpty' => $this->skipOnEmpty,
37 2
            'skipOnError' => $this->skipOnError,
38
        ];
39
    }
40
}
41