Completed
Push — master ( c628d7...8aa25c )
by Miloš
01:17
created

ResolverFactory::create()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7.0178

Importance

Changes 0
Metric Value
cc 7
nc 7
nop 1
dl 0
loc 24
ccs 13
cts 14
cp 0.9286
crap 7.0178
rs 8.6026
c 0
b 0
f 0
1
<?php
2
3
namespace Laganica\Di\Resolver;
4
5
use Closure;
6
use InvalidArgumentException;
7
use Laganica\Di\Definition\AliasDefinition;
8
use Laganica\Di\Definition\BindDefinition;
9
use Laganica\Di\Definition\FactoryDefinition;
10
use Laganica\Di\Definition\ValueDefinition;
11
use Psr\Container\ContainerInterface;
12
13
/**
14
 * Class ResolverFactory
15
 *
16
 * @package Laganica\Di\Resolver
17
 */
18
class ResolverFactory implements ResolverFactoryInterface
19
{
20
    /**
21
     * @var ContainerInterface
22
     */
23
    private $container;
24
25
    /**
26
     * @param ContainerInterface $container
27
     */
28 6
    public function setContainer(ContainerInterface $container): void
29
    {
30 6
        $this->container = $container;
31 6
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36 6
    public function create($definition): ResolverInterface
37
    {
38
        switch (true) {
39 6
            case $definition instanceof BindDefinition:
40 1
                return new BindResolver($this->container);
41
42 5
            case $definition instanceof FactoryDefinition:
43 2
                return new FactoryResolver($this->container);
44
45 4
            case $definition instanceof ValueDefinition:
46 1
                return new ValueResolver($this->container);
47
48 3
            case $definition instanceof AliasDefinition:
49 1
                return new AliasResolver($this->container);
50
51 2
            case $definition instanceof Closure:
52 1
                return new ClosureResolver($this->container);
53
54 1
            case is_string($definition):
55 1
                return new ClassResolver($this->container);
56
        }
57
58
        throw new InvalidArgumentException('Invalid definition found. Allowed definitions are bind(), value(), factory(), alias(), Closure or string');
59
    }
60
}
61