Completed
Push — master ( aa8aa9...a51ad4 )
by Peter
02:05
created

SwitchQueryHandlerTrait::makeHandleMethodName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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