HandlerLocator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHandlerForCommand() 0 10 2
A getHandlerClassName() 0 4 1
1
<?php
2
3
namespace Mosaic\CommandBus\Adapters\Tactician;
4
5
use League\Tactician\Exception\MissingHandlerException;
6
use League\Tactician\Handler\Locator\HandlerLocator as HandlerLocatorInterface;
7
use Mosaic\Container\Container;
8
9
class HandlerLocator implements HandlerLocatorInterface
10
{
11
    /**
12
     * @var Container
13
     */
14
    private $container;
15
16
    /**
17
     * Locator constructor.
18
     * @param Container $container
19
     */
20 8
    public function __construct(Container $container)
21
    {
22 8
        $this->container = $container;
23 8
    }
24
25
    /**
26
     * Retrieves the handler for a specified command
27
     *
28
     * @param string $commandName
29
     *
30
     * @throws MissingHandlerException
31
     * @return object
32
     */
33 8
    public function getHandlerForCommand($commandName)
34
    {
35 8
        $handler = $this->getHandlerClassName($commandName);
36
37 8
        if (!class_exists($handler)) {
38 1
            throw MissingHandlerException::forCommand($commandName);
39
        }
40
41 7
        return $this->container->make($handler);
42
    }
43
44
    /**
45
     * @param $commandName
46
     * @return string
47
     */
48 8
    protected function getHandlerClassName($commandName)
49
    {
50 8
        return $commandName . 'Handler';
51
    }
52
}
53