Completed
Push — master ( e0a1f5...b066a3 )
by Korotkov
03:07 queued 01:32
created

CommandRegistry::executeCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Command;
11
12
/**
13
 * Class CommandRegistry
14
 * @package Behavioral\Command
15
 */
16
class CommandRegistry
17
{
18
19
    /**
20
     * @var DeviceInterface
21
     */
22
    protected $device;
23
    /**
24
     * @var array
25
     */
26
    protected $commandsRegistry = [];
27
28
    /**
29
     * CommandRegistry constructor.
30
     * @param DeviceInterface $device
31
     */
32
    public function __construct(DeviceInterface $device)
33
    {
34
        $this->device = $device;
35
    }
36
37
    /**
38
     * @param CommandInterface $command
39
     * @param string           $name
40
     */
41
    public function setCommand(CommandInterface $command, string $name): void
42
    {
43
        $this->commandsRegistry[$name] = $command;
44
    }
45
46
    /**
47
     * @param string $name
48
     */
49
    public function executeCommand(string $name): void
50
    {
51
        if (isset($this->commandsRegistry[$name])) {
52
            $this->commandsRegistry[$name]->execute($this->device);
53
        }
54
    }
55
}
56