Passed
Push — master ( 89f940...819311 )
by Alexander
02:27
created

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