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

WhenTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A when() 0 5 1
A getWhen() 0 3 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