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

SwitchCommandHandlerTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

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