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

SkipOnEmpty   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A __invoke() 0 7 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