Completed
Push — master ( 584535...0a347f )
by Miloš
01:10
created

BindResolver::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
8
/**
9
 * Class BindResolver
10
 *
11
 * @package Laganica\Di\Resolver
12
 */
13
class BindResolver extends ReflectionResolver
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 1
    public function resolve(DefinitionInterface $definition)
19
    {
20 1
        $class = $definition->getValue();
21
22 1
        if (!is_string($class)) {
23
            throw new InvalidArgumentException('Value of $definition->getValue() must be string');
24
        }
25
26 1
        if (!class_exists($class)) {
27
            throw new InvalidArgumentException('Value of $definition->getValue() must be classname');
28
        }
29
30 1
        $params = $this->getConstructorParams($class);
31
32 1
        return new $class(...$params);
33
    }
34
}
35