Completed
Push — master ( 0a347f...cdbc95 )
by Miloš
01:25
created

ClassResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 16 3
1
<?php
2
3
namespace Laganica\Di\Resolver;
4
5
use InvalidArgumentException;
6
use Laganica\Di\Definition\DefinitionInterface;
7
use Laganica\Di\Exception\NotFoundException;
8
9
/**
10
 * Class AutowireResolver
11
 *
12
 * @package Laganica\Di\Resolver
13
 */
14
class ClassResolver extends ReflectionResolver
15
{
16
    /**
17
     * @inheritDoc
18
     */
19 4
    public function resolve(DefinitionInterface $definition)
20
    {
21 4
        $class = $definition->getValue();
22
23 4
        if (!is_string($class)) {
24
            throw new InvalidArgumentException('Value of $definition->getValue() must be string');
25
        }
26
27 4
        if (!class_exists($class)) {
28
            NotFoundException::create($class);
29
        }
30
31 4
        $params = $this->getConstructorParams($class);
32
33 4
        return new $class(...$params);
34
    }
35
}
36