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

DirectBindingQueryHandlerLocator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerHandler() 4 4 1
A getQueryHandler() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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