Passed
Pull Request — master (#399)
by
unknown
02:33
created

DataSetNormalizer::normalize()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Helper;
6
7
use Yiisoft\Validator\DataSet\ArrayDataSet;
8
use Yiisoft\Validator\DataSet\ObjectDataSet;
9
use Yiisoft\Validator\DataSet\SingleValueDataSet;
10
use Yiisoft\Validator\DataSetInterface;
11
12
use function is_array;
13
use function is_object;
14
15
final class DataSetNormalizer
16
{
17 826
    public static function normalize(mixed $data): DataSetInterface
18
    {
19 826
        if ($data instanceof DataSetInterface) {
20 79
            return $data;
21
        }
22
23 752
        if (is_object($data)) {
24 42
            return new ObjectDataSet($data);
25
        }
26
27 714
        if (is_array($data)) {
28 170
            return new ArrayDataSet($data);
29
        }
30
31 573
        return new SingleValueDataSet($data);
32
    }
33
}
34