Passed
Push — master ( aa29a1...1017dc )
by Alexander
02:31
created

DefinitionNormalizer::normalize()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 14
ccs 7
cts 8
cp 0.875
crap 4.0312
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
use Yiisoft\Factory\Definition\ArrayDefinition;
8
use Yiisoft\Factory\Definition\DefinitionInterface;
9
use Yiisoft\Factory\Definition\Normalizer;
10
use Yiisoft\Factory\Exception\InvalidConfigException;
11
use function is_array;
12
13
/**
14
 * @internal
15
 */
16
final class DefinitionNormalizer
17
{
18
    /**
19
     * @param mixed $definition
20
     *
21
     * @throws InvalidConfigException
22
     */
23 92
    public static function normalize($definition, string $id = null): DefinitionInterface
24
    {
25 92
        if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
26 32
            [$class, $constructorArguments, $methodsAndProperties] = $definition;
27
28 32
            $class = $class ?? $id;
29 32
            if ($class === null) {
30
                throw new InvalidConfigException('Invalid definition: don\'t set class name.');
31
            }
32
33 32
            return ArrayDefinition::fromPreparedData($class, $constructorArguments, $methodsAndProperties);
34
        }
35
36 92
        return Normalizer::normalize($definition, $id);
37
    }
38
}
39