HandlerLocator::getHandlerClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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