Passed
Pull Request — master (#240)
by Dmitriy
03:45
created

Callback::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
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 Closure;
8
use JetBrains\PhpStorm\ArrayShape;
9
use Yiisoft\Validator\ParametrizedRuleInterface;
10
use Yiisoft\Validator\BeforeValidationInterface;
11
use Yiisoft\Validator\Rule\Trait\HandlerClassNameTrait;
12
use Yiisoft\Validator\Rule\Trait\BeforeValidationTrait;
13
use Yiisoft\Validator\Rule\Trait\RuleNameTrait;
14
use Yiisoft\Validator\ValidationContext;
15
16
final class Callback implements ParametrizedRuleInterface, BeforeValidationInterface
17
{
18
    use BeforeValidationTrait;
19
    use HandlerClassNameTrait;
20
    use RuleNameTrait;
21
22 4
    public function __construct(
23
        /**
24
         * @var callable
25
         */
26
        private $callback,
27
        private bool $skipOnEmpty = false,
28
        private bool $skipOnError = false,
29
        /**
30
         * @var Closure(mixed, ValidationContext):bool|null
31
         */
32
        private ?Closure $when = null,
33
    ) {
34
    }
35
36
    /**
37
     * @return callable
38
     */
39 7
    public function getCallback(): callable
40
    {
41 7
        return $this->callback;
42
    }
43
44 2
    #[ArrayShape(['skipOnEmpty' => 'bool', 'skipOnError' => 'bool'])]
45
    public function getOptions(): array
46
    {
47
        return [
48 2
            'skipOnEmpty' => $this->skipOnEmpty,
49 2
            'skipOnError' => $this->skipOnError,
50
        ];
51
    }
52
}
53