LastPartOfClassName::getMethodName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 3
c 1
b 1
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Tactician\Handler\Mapping\MethodName;
6
7
use function strpos;
8
use function strrpos;
9
use function strtolower;
10
use function substr;
11
12
/**
13
 * Assumes the method is only the last portion of the class name.
14
 *
15
 * Examples:
16
 *  - \MyGlobalCommand    => $handler->myGlobalCommand()
17
 *  - \My\App\CreateUser  => $handler->createUser()
18
 */
19
final class LastPartOfClassName implements MethodNameInflector
20
{
21 7
    public function getMethodName(string $commandClassNameName): string
22
    {
23
        // If class name has a namespace separator, only take last portion
24 7
        if (strpos($commandClassNameName, '\\') !== false) {
25 3
            $commandClassNameName = substr($commandClassNameName, strrpos($commandClassNameName, '\\') + 1);
26
        }
27
28 7
        return strtolower($commandClassNameName[0]) . substr($commandClassNameName, 1);
29
    }
30
}
31