Completed
Push — master ( 134712...8789de )
by Peter
06:34
created

getQueryHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * Carousel project.
5
 *
6
 * @author Peter Gribanov <[email protected]>
7
 */
8
9
namespace GpsLab\Component\Query\Handler\Locator;
10
11
use GpsLab\Component\Query\Handler\QueryHandler;
12
use GpsLab\Component\Query\Query;
13
14 View Code Duplication
class DirectBindingQueryHandlerLocator implements QueryHandlerLocator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @var QueryHandler[]
18
     */
19
    private $handlers = [];
20
21
    /**
22
     * Bind query handler to concrete query by class name.
23
     *
24
     * @param string       $query_name
25
     * @param QueryHandler $handler
26
     */
27
    public function registerHandler($query_name, QueryHandler $handler)
28
    {
29
        $this->handlers[$query_name] = $handler;
30
    }
31
32
    /**
33
     * @param Query $query
34
     *
35
     * @return QueryHandler|null
36
     */
37
    public function getQueryHandler(Query $query)
38
    {
39
        $query_name = get_class($query);
40
41
        return isset($this->handlers[$query_name]) ? $this->handlers[$query_name] : null;
42
    }
43
}
44