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

SwitchQueryHandlerTrait::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Query\Handler;
12
13
use GpsLab\Component\Query\Query;
14
15 View Code Duplication
trait SwitchQueryHandlerTrait
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...
16
{
17
    /**
18
     * @param Query $query
19
     *
20
     * @return mixed
21
     */
22
    public function handle(Query $query)
23
    {
24
        return call_user_func([$this, $this->getHandleMethod($query)], $query);
25
    }
26
27
    /**
28
     * @param Query $query
29
     *
30
     * @return string
31
     */
32
    private function getHandleMethod(Query $query)
33
    {
34
        $class = get_class($query);
35
36
        if ('Query' === substr($class, -5)) {
37
            $class = substr($class, 0, -5);
38
        }
39
40
        $class = str_replace('_', '\\', $class); // convert names for classes not in namespace
41
        $parts = explode('\\', $class);
42
43
        return 'handle'.end($parts);
44
    }
45
}
46