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

Callback   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getCallback() 0 3 1
A getHandlerClassName() 0 3 1
A getOptions() 0 6 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