Passed
Pull Request — master (#376)
by
unknown
03:18
created

SkipOnEmptyNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

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