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

Embedded   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 41
ccs 6
cts 11
cp 0.5455
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 5 1
A getPropertyVisibility() 0 3 1
A __construct() 0 14 1
A getHandlerClassName() 0 3 1
A getName() 0 3 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