Passed
Pull Request — master (#222)
by Alexander
02:58
created

Callback   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 34
ccs 12
cts 13
cp 0.9231
rs 10
c 1
b 0
f 0
wmc 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Closure;
8
use JetBrains\PhpStorm\ArrayShape;
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\ParametrizedRuleInterface;
12
13
final class Callback implements ParametrizedRuleInterface
14
{
15
    use HandlerClassNameTrait;
16
    use RuleNameTrait;
17
18 4
    public function __construct(
19
        /**
20
         * @var callable
21
         */
22
        private $callback,
23
        private bool $skipOnEmpty = false,
24
        private bool $skipOnError = false,
25
        private ?Closure $when = null,
26
    ) {
27
    }
28
29
    /**
30
     * @return callable
31
     */
32 7
    public function getCallback(): callable
33
    {
34 7
        return $this->callback;
35
    }
36
37
    /**
38
     * @return bool
39
     */
40
    public function isSkipOnEmpty(): bool
41
    {
42
        return $this->skipOnEmpty;
43
    }
44
45
    /**
46
     * @return bool
47
     */
48
    public function isSkipOnError(): bool
49
    {
50
        return $this->skipOnError;
51
    }
52
53
    /**
54
     * @return Closure|null
55
     */
56
    public function getWhen(): ?Closure
57
    {
58
        return $this->when;
59
    }
60
61 2
    #[ArrayShape(['skipOnEmpty' => 'bool', 'skipOnError' => 'bool'])]
62
    public function getOptions(): array
63
    {
64
        return [
65 2
            'skipOnEmpty' => $this->skipOnEmpty,
66 2
            'skipOnError' => $this->skipOnError,
67
        ];
68
    }
69
}
70