ContainerMapLocator::setHandlerForCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 2
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace JCIT\jobqueue\components;
5
6
use League\Tactician\Exception\MissingHandlerException;
7
use League\Tactician\Handler\Locator\HandlerLocator;
8
use yii\di\Container;
9
10
class ContainerMapLocator implements HandlerLocator
11
{
12
    private array $map = [];
13
14 2
    public function __construct(
15
        private Container $container
16
    ) {
17 2
    }
18
19
    /**
20
     * @param string $commandName
21
     */
22 2
    public function getHandlerForCommand($commandName): object
23
    {
24 2
        if (!isset($this->map[$commandName])) {
25 1
            throw MissingHandlerException::forCommand($commandName);
26
        }
27 1
        return $this->container->get($this->map[$commandName]);
28
    }
29
30 1
    public function setHandlerForCommand(string $commandName, string $handler): self
31
    {
32 1
        $this->map[$commandName] = $handler;
33 1
        return $this;
34
    }
35
}
36