NativeMapResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A resolve() 0 8 2
1
<?php
2
3
namespace Depot\Resolution;
4
5
use Depot\Command;
6
use Depot\Container;
7
use Depot\Container\NativeContainer;
8
use Depot\Exception\UnresolvableHandlerException;
9
use Depot\HandlerResolver;
10
11
final class NativeMapResolver implements HandlerResolver
12
{
13
    /**
14
     * @var string[]
15
     */
16
    private $commands;
17
    /**
18
     * @var Container
19
     */
20
    private $container;
21
22
    /**
23
     * NativeMapResolver constructor
24
     * @param string[] $commands
25
     * @param Container $container
26
     */
27
    public function __construct(array $commands, Container $container = null)
28
    {
29
        $this->commands = $commands;
30
        $this->container = $container ?: new NativeContainer;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function resolve(Command $command)
37
    {
38
        if (array_key_exists($command = get_class($command), $this->commands)) {
39
            return $this->container->make($this->commands[$command]);
40
        }
41
42
        throw new UnresolvableHandlerException("Unable to resolve handler for $command");
43
    }
44
}
45