Test Failed
Push — refactoring ( b75fb9...3e325f )
by Sergei
02:11
created

DefinitionNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 14 4
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
    public static function normalize($definition, string $id = null): DefinitionInterface
24
    {
25
        if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
26
            [$class, $constructorArguments, $methodsAndProperties] = $definition;
27
28
            $class = $class ?? $id;
29
            if ($class === null) {
30
                throw new InvalidConfigException('Invalid definition: don\'t set class name.');
31
            }
32
33
            return ArrayDefinition::fromPreparedData($class, $constructorArguments, $methodsAndProperties);
0 ignored issues
show
Bug introduced by
The method fromPreparedData() does not exist on Yiisoft\Factory\Definition\ArrayDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            return ArrayDefinition::/** @scrutinizer ignore-call */ fromPreparedData($class, $constructorArguments, $methodsAndProperties);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        }
35
36
        return Normalizer::normalize($definition, $id);
37
    }
38
}
39