Passed
Pull Request — master (#370)
by Sergei
03:04
created

DataSetHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
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 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Yiisoft\Validator\DataSet\ArrayDataSet;
8
use Yiisoft\Validator\DataSet\ObjectDataSet;
9
use Yiisoft\Validator\DataSet\SingleValueDataSet;
10
11
use function is_array;
12
use function is_object;
13
14
final class DataSetHelper
15
{
16 716
    public static function normalize(mixed $data): DataSetInterface
17
    {
18 716
        if ($data instanceof DataSetInterface) {
19 71
            return $data;
20
        }
21
22 650
        if (is_object($data)) {
23 38
            return new ObjectDataSet($data);
24
        }
25
26 616
        if (is_array($data)) {
27 110
            return new ArrayDataSet($data);
28
        }
29
30 532
        return new SingleValueDataSet($data);
31
    }
32
}
33