Passed
Push — master ( c6159b...7fa890 )
by
unknown
02:39
created

SkipOnEmpty::__invoke()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.2222
cc 6
nc 8
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\SkipOnEmptyCallback;
6
7
use function is_string;
8
9
final class SkipOnEmpty
10
{
11 53
    public function __construct(private bool $trimString = false)
12
    {
13
    }
14
15 60
    public function __invoke(mixed $value, bool $isAttributeMissing): bool
16
    {
17 60
        if (is_string($value) && $this->trimString) {
18 20
            $value = trim($value);
19
        }
20
21 60
        return $isAttributeMissing || $value === null || $value === [] || $value === '';
22
    }
23
}
24