Passed
Push — master ( 59a93e...603998 )
by Alexander
03:10
created

DefinitionNormalizer::normalize()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
use Yiisoft\Definitions\ArrayDefinition;
8
use Yiisoft\Definitions\Contract\DefinitionInterface;
9
use Yiisoft\Definitions\Exception\InvalidConfigException;
10
use Yiisoft\Definitions\Helpers\Normalizer;
11
12
use function is_array;
13
14
/**
15
 * @internal Normalizes a definition.
16
 */
17
final class DefinitionNormalizer
18
{
19
    /**
20
     * @param mixed $definition Definition to normalize.
21
     * @param string $id Service ID.
22
     *
23
     * @throws InvalidConfigException If configuration is not valid.
24
     */
25 79
    public static function normalize($definition, string $id): DefinitionInterface
26
    {
27 79
        if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
28 33
            return ArrayDefinition::fromPreparedData(
29 33
                $definition['class'] ?? $id,
30 33
                $definition['__construct()'],
31 33
                $definition['methodsAndProperties']
32
            );
33
        }
34
35 79
        if ($definition instanceof ExtensibleService) {
36 4
            return $definition;
37
        }
38
39 79
        return Normalizer::normalize($definition, $id);
40
    }
41
}
42