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

SwitchCommandHandlerTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A makeHandleMethodName() 0 13 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;
12
13
use GpsLab\Component\Command\Command;
14
15
trait SwitchCommandHandlerTrait
16
{
17
    /**
18
     * @param Command $command
19
     */
20 2
    public function handle(Command $command)
21
    {
22 2
        call_user_func([$this, $this->makeHandleMethodName($command)], $command);
23 2
    }
24
25
    /**
26
     * @param Command $command
27
     *
28
     * @return string
29
     */
30 2
    private function makeHandleMethodName(Command $command)
31
    {
32 2
        $class = get_class($command);
33
34 2
        if ('Command' === substr($class, -7)) {
35 1
            $class = substr($class, 0, -7);
36 1
        }
37
38 2
        $class = str_replace('_', '\\', $class); // convert names for classes not in namespace
39 2
        $parts = explode('\\', $class);
40
41 2
        return 'handle'.end($parts);
42
    }
43
}
44