Completed
Pull Request — master (#2)
by lee
06:59
created

DirectBindingCommandHandlerLocator::findHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\Command;
14
15
class DirectBindingCommandHandlerLocator implements CommandHandlerLocator
16
{
17
    /**
18
     * @var callable[]
19
     */
20
    private $handlers = [];
21
22
    /**
23
     * Bind command handler to concrete command by class name.
24
     *
25
     * @param string   $command_name
26
     * @param callable $handler
27
     */
28
    public function registerHandler($command_name, callable $handler)
29
    {
30
        $this->handlers[$command_name] = $handler;
31
    }
32
33
    /**
34
     * @param Command $command
35
     *
36
     * @return callable|null
37
     */
38
    public function findHandler(Command $command)
39
    {
40
        $command_name = get_class($command);
41
42
        return isset($this->handlers[$command_name]) ? $this->handlers[$command_name] : null;
43
    }
44
}
45