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

DefinitionNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 15 4
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