Passed
Pull Request — master (#300)
by Alexander
06:13 queued 03:06
created

SkipOnEmptyTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A skipOnEmpty() 0 5 1
A getSkipOnEmpty() 0 3 1
A getSkipOnEmptyOption() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Trait;
6
7
use function is_bool;
8
9
trait SkipOnEmptyTrait
10
{
11 93
    public function skipOnEmpty(bool|callable|null $value): static
12
    {
13 93
        $new = clone $this;
14 93
        $new->skipOnEmpty = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property skipOnEmpty does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15 93
        return $new;
16
    }
17
18 100
    public function getSkipOnEmpty(): bool|callable|null
19
    {
20 100
        return $this->skipOnEmpty;
21
    }
22
23 94
    private function getSkipOnEmptyOption(): bool
24
    {
25 94
        if (is_bool($this->skipOnEmpty)) {
26 41
            return $this->skipOnEmpty;
27
        }
28
29 53
        return ! ($this->skipOnEmpty === null)
30
31
32
33
         ;
34
    }
35
}
36