Passed
Pull Request — master (#300)
by Sergei
02:36
created

SkipOnEmptyNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use InvalidArgumentException;
8
use Yiisoft\Validator\SkipOnEmptyCallback\SkipOnEmpty;
9
10
use function is_callable;
11
12
/**
13
 * @internal
14
 */
15
final class SkipOnEmptyNormalizer
16
{
17 3
    public static function normalize(mixed $skipOnEmpty): ?callable
18
    {
19 3
        if ($skipOnEmpty === false) {
20 1
            return null;
21
        }
22
23 2
        if ($skipOnEmpty === true) {
24 1
            return new SkipOnEmpty();
25
        }
26
27 1
        if (!is_callable($skipOnEmpty)) {
28
            throw new InvalidArgumentException('$skipOnEmpty must be a boolean or a callable.');
29
        }
30
31 1
        return $skipOnEmpty;
32
    }
33
}
34