Passed
Pull Request — master (#300)
by Alexander
06:13 queued 03:06
created

SkipOnEmptyNormalizer::normalize()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 9.6111
cc 5
nc 4
nop 1
crap 5.0488
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 659
    public static function normalize(mixed $skipOnEmpty): ?callable
19
    {
20 659
        if ($skipOnEmpty === false || $skipOnEmpty === null) {
21 631
            return new SkipNone();
22
        }
23
24 96
        if ($skipOnEmpty === true) {
25 7
            return new SkipOnEmpty();
26
        }
27
28 93
        if (is_callable($skipOnEmpty)) {
29 93
            return $skipOnEmpty;
30
        }
31
32
        throw new InvalidArgumentException('$skipOnEmpty must be a null, a boolean or a callable.');
33
    }
34
}
35