Passed
Pull Request — master (#331)
by Sergei
02:46
created

WhenTrait::when()   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
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
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 WhenTrait
11
{
12
    /**
13
     * @psalm-param Closure(mixed, ValidationContext):bool|null $value
14
     */
15 1
    public function when(?Closure $value): static
16
    {
17 1
        $new = clone $this;
18 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...
19 1
        return $new;
20
    }
21
22
    /**
23
     * @psalm-return Closure(mixed, ValidationContext):bool|null
24
     */
25 116
    public function getWhen(): ?Closure
26
    {
27 116
        return $this->when;
28
    }
29
}
30