Passed
Pull Request — master (#300)
by Sergei
03:14
created

SkipOnEmptyTrait::getSkipOnEmptyOption()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 10
cc 3
nc 3
nop 0
crap 3.0416
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
        if ($this->skipOnEmpty === null) {
30 53
            return false;
31
        }
32
33
        return true;
34
    }
35
}
36