DefinitionNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di\Helpers;
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
use Yiisoft\Di\ExtensibleService;
12
13
use function is_array;
14
15
/**
16
 * @internal Normalizes a definition.
17
 */
18
final class DefinitionNormalizer
19
{
20
    /**
21
     * @param mixed $definition Definition to normalize.
22
     * @param string $id Service ID.
23
     *
24
     * @throws InvalidConfigException If configuration is not valid.
25
     */
26 123
    public static function normalize(mixed $definition, string $id): DefinitionInterface
27
    {
28 123
        if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
29
            /** @psalm-suppress MixedArgument Definition should be valid {@see Container::$validate} */
30 39
            return ArrayDefinition::fromPreparedData(
31 39
                $definition['class'] ?? $id,
32 39
                $definition['__construct()'],
33 39
                $definition['methodsAndProperties']
34 39
            );
35
        }
36
37 123
        if ($definition instanceof ExtensibleService) {
38 6
            return $definition;
39
        }
40
41 123
        return Normalizer::normalize($definition, $id);
42
    }
43
}
44