Passed
Push — master ( f0b656...d1524d )
by Alexander
02:42
created

BeforeValidationTrait::skipOnError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Trait;
6
7
use Closure;
8
use Yiisoft\Validator\ValidationContext;
9
10
trait BeforeValidationTrait
11
{
12 1
    public function skipOnError(bool $value): static
13
    {
14 1
        $new = clone $this;
15 1
        $new->skipOnError = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property skipOnError does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16 1
        return $new;
17
    }
18
19 96
    public function shouldSkipOnError(): bool
20
    {
21 96
        return $this->skipOnError;
22
    }
23
24
    /**
25
     * @psalm-param Closure(mixed, ValidationContext):bool|null $value
26
     */
27 1
    public function when(?Closure $value): static
28
    {
29 1
        $new = clone $this;
30 1
        $new->when = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property when does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31 1
        return $new;
32
    }
33
34
    /**
35
     * @psalm-return Closure(mixed, ValidationContext):bool|null
36
     */
37 95
    public function getWhen(): ?Closure
38
    {
39 95
        return $this->when;
40
    }
41
}
42