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

DirectBindingCommandHandlerLocator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 30
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerHandler() 0 4 1
A findHandler() 0 6 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\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