Completed
Push — master ( b7963c...112a6b )
by Ross
12s
created

ClassNameInflector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A inflect() 0 11 2
1
<?php
2
3
namespace League\Tactician\Handler\MethodNameInflector;
4
5
/**
6
 * Assumes the method is only the last portion of the class name.
7
 *
8
 * Examples:
9
 *  - \MyGlobalCommand    => $handler->myGlobalCommand()
10
 *  - \My\App\CreateUser  => $handler->createUser()
11
 */
12
class ClassNameInflector implements MethodNameInflector
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 7
    public function inflect($command, $commandHandler)
18
    {
19 7
        $commandName = get_class($command);
20
21
        // If class name has a namespace separator, only take last portion
22 7
        if (strpos($commandName, '\\') !== false) {
23 3
            $commandName = substr($commandName, strrpos($commandName, '\\') + 1);
24
        }
25
26 7
        return strtolower($commandName[0]) . substr($commandName, 1);
27
    }
28
}
29