Passed
Branch php8 (4b68f8)
by Mike
06:45
created

ClassnameLaminasLocator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHandlerForCommand() 0 14 3
1
<?php
2
namespace TacticianModule\Locator;
3
4
use League\Tactician\Exception\MissingHandlerException;
5
use League\Tactician\Handler\Locator\HandlerLocator;
6
use Psr\Container\ContainerInterface;
7
8
class ClassnameLaminasLocator implements HandlerLocator
9
{
10
    private $container;
11
12 3
    public function __construct(ContainerInterface $container)
13
    {
14 3
        $this->container = $container;
15 3
    }
16
17
    /**
18
     * Retrieves the handler for a specified command
19
     *
20
     * @param string $commandName
21
     *
22
     * @return mixed
23
     *
24
     * @throws MissingHandlerException
25
     */
26 3
    public function getHandlerForCommand($commandName)
27
    {
28 3
        $handlerFQCN = $commandName . 'Handler';
29
30 3
        if ($this->container->has($handlerFQCN)) {
31 1
            return $this->container->get($handlerFQCN);
32
        }
33
34 2
        if (class_exists($handlerFQCN)) {
35 1
            return new $handlerFQCN();
36
        }
37
38 1
        throw MissingHandlerException::forCommand($commandName);
39
    }
40
}
41