Passed
Pull Request — master (#296)
by Sergei
02:55
created

Embedded::getPropertyVisibility()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Attribute;
8
use Closure;
9
use ReflectionProperty;
10
use Yiisoft\Validator\BeforeValidationInterface;
11
use Yiisoft\Validator\Rule\Trait\BeforeValidationTrait;
12
use Yiisoft\Validator\SerializableRuleInterface;
13
use Yiisoft\Validator\ValidationContext;
14
15
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
16
final class Embedded implements SerializableRuleInterface, BeforeValidationInterface
17
{
18
    use BeforeValidationTrait;
19
20 10
    public function __construct(
21
        private int $propertyVisibility = ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC,
22
        private bool $skipOnEmpty = false,
23
        /**
24
         * @var callable|null
25
         */
26
        private $skipOnEmptyCallback = null,
27
        private bool $skipOnError = false,
28
        /**
29
         * @var Closure(mixed, ValidationContext):bool|null
30
         */
31
        private ?Closure $when = null,
32
    ) {
33 10
        $this->initSkipOnEmptyProperties($skipOnEmpty, $skipOnEmptyCallback);
34
    }
35
36
    public function getName(): string
37
    {
38
        return 'Embedded';
39
    }
40
41 4
    public function getHandlerClassName(): string
42
    {
43 4
        return EmbeddedHandler::class;
44
    }
45
46 6
    public function getPropertyVisibility(): int
47
    {
48 6
        return $this->propertyVisibility;
49
    }
50
51
    public function getOptions(): array
52
    {
53
        return [
54
            'skipOnEmpty' => $this->skipOnEmpty,
55
            'skipOnError' => $this->skipOnError,
56
        ];
57
    }
58
}
59