Completed
Push — master ( 4d53e8...c0eace )
by Korotkov
05:52 queued 01:46
created

CommandRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2017, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace Behavioral\Command;
12
13
/**
14
 * Class CommandRegistry
15
 * @package Behavioral\Command
16
 */
17
class CommandRegistry
18
{
19
20
    /**
21
     * @var array
22
     */
23
    protected $commandsRegistry = [];
24
25
    /**
26
     * @var InterfaceDevice
27
     */
28
    protected $device;
29
30
    /**
31
     * CommandRegistry constructor.
32
     * @param InterfaceDevice $device
33
     */
34
    public function __construct(InterfaceDevice $device)
35
    {
36
        $this->device = $device;
37
    }
38
39
    /**
40
     * @return InterfaceDevice
41
     */
42
    public function getDevice(): InterfaceDevice
43
    {
44
        return $this->device;
45
    }
46
47
    /**
48
     * @param        $command
49
     * @param string $type
50
     */
51
    public function setCommand($command, string $type): void
52
    {
53
        $this->commandsRegistry[$type] = $command;
54
    }
55
56
    /**
57
     * @param string $type
58
     * @return mixed
59
     */
60
    public function getCommand(string $type)
61
    {
62
        if (isset($this->commandsRegistry[$type])) {
63
            return $this->commandsRegistry[$type]->execute($this->getDevice());
64
        } else {
65
            print 'Cannot find command ' . $type;
66
        }
67
    }
68
}
69