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

ClassNameInflector::inflect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 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