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

ClassResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 16
ccs 6
cts 8
cp 0.75
crap 3.1406
rs 9.7333
c 0
b 0
f 0
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