Completed
Push — master ( aa8aa9...a51ad4 )
by Peter
02:05
created

DirectBindingCommandHandlerLocator::findHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Command\Handler\Locator;
12
13
use GpsLab\Component\Command\Handler\CommandHandler;
14
use GpsLab\Component\Command\Command;
15
16
class DirectBindingCommandHandlerLocator implements CommandHandlerLocator
17
{
18
    /**
19
     * @var CommandHandler[]
20
     */
21
    private $handlers = [];
22
23
    /**
24
     * Bind command handler to concrete command by class name.
25
     *
26
     * @param string         $command_name
27
     * @param CommandHandler $handler
28
     */
29 2
    public function registerHandler($command_name, CommandHandler $handler)
30
    {
31 2
        $this->handlers[$command_name] = $handler;
32 2
    }
33
34
    /**
35
     * @param Command $command
36
     *
37
     * @return CommandHandler|null
38
     */
39 2
    public function findHandler(Command $command)
40
    {
41 2
        $command_name = get_class($command);
42
43 2
        return isset($this->handlers[$command_name]) ? $this->handlers[$command_name] : null;
44
    }
45
}
46