Passed
Push — master ( 79aac2...b14f6f )
by Alexander
03:30
created

SkipOnEmptyTrait::getSkipOnEmptyOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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