Executor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addExecutor() 0 6 1
A getExecutor() 0 8 2
A execute() 0 8 2
1
<?php
2
3
namespace Thruster\Component\Actions;
4
5
use function Funct\arrayKeyNotExists;
6
use Thruster\Component\Actions\Exception\ActionExecutorNotFoundException;
7
8
/**
9
 * Class Executor
10
 *
11
 * @package Thruster\Component\Actions
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
class Executor implements ExecutorInterface
15
{
16
    /**
17
     * @var ActionExecutorInterface[]
18
     */
19
    protected $executors;
20
21 10
    public function __construct()
22
    {
23 10
        $this->executors = [];
24 10
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29 2
    public function addExecutor(string $actionName, ActionExecutorInterface $executor) : self
30
    {
31 2
        $this->executors[$actionName] = $executor;
32
33 2
        return $this;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39 3
    public function getExecutor(string $actionName) : ActionExecutorInterface
40
    {
41 3
        if (arrayKeyNotExists($actionName, $this->executors)) {
42 1
            throw new ActionExecutorNotFoundException($actionName);
43
        }
44
45 2
        return $this->executors[$actionName];
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51 8
    public function execute(ActionInterface $action)
52
    {
53 8
        if ($action instanceof ExecutorLessInterface) {
54 7
            return $action->parseArguments($this);
55
        } else {
56 1
            return $this->getExecutor($action->getName())->execute($action->parseArguments($this));
57
        }
58
    }
59
}
60