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

BindResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

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 2

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
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