HandlerLocator::getHandlerForCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
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