HandlerLocator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 11
cts 11
cp 1
c 0
b 0
f 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getHandlerForCommand() 0 13 1
1
<?php declare(strict_types = 1);
2
3
namespace Simplex\Quickstart\Shared\CommandBus;
4
5
use League\Tactician\Handler\Locator\HandlerLocator as LocatorInterface;
6
use Psr\Container\ContainerInterface;
7
8
final class HandlerLocator implements LocatorInterface
9
{
10
    private const COMMAND_HANDLER_NAMESPACE_PART = 'CommandHandler';
11
    private const COMMAND_HANDLER_CLASS_SUFFIX = 'Handler';
12
13
    /** @var ContainerInterface */
14
    private $container;
15
16 1
    public function __construct(ContainerInterface $container)
17
    {
18 1
        $this->container = $container;
19 1
    }
20
21
    /** @return mixed */
22 1
    public function getHandlerForCommand($commandName)
23
    {
24 1
        $namespaceParts = explode('\\', $commandName);
25
26 1
        $commandClassName = array_pop($namespaceParts);
27 1
        array_pop($namespaceParts); // remove 'Command' namespace part
28
29 1
        $namespaceParts[] = self::COMMAND_HANDLER_NAMESPACE_PART;
30 1
        $namespaceParts[] = $commandClassName . self::COMMAND_HANDLER_CLASS_SUFFIX;
31
32 1
        $handlerName = implode('\\', $namespaceParts);
33
34 1
        return $this->container->get($handlerName);
35
    }
36
}
37