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

DataSetNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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\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