Completed
Push — master ( 09c84d...fe53c9 )
by Dmitry
02:55
created

NearbyHandlerLocator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 19
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHandlerForCommand() 0 16 2
1
<?php
2
3
namespace hiapi\bus;
4
5
use League\Tactician\Handler\Locator\HandlerLocator;
6
use ReflectionClass;
7
use yii\base\UnknownClassException;
8
9
class NearbyHandlerLocator implements HandlerLocator
10
{
11
    public function getHandlerForCommand($class)
12
    {
13
        $reflector = new ReflectionClass($class);
14
        $dir = dirname($reflector->getFileName());
15
16
        $commandName = $reflector->getShortName();
17
        $handlerName = substr($commandName, 0, strrpos($commandName, 'Command')) . 'Handler';
18
19
        $path = $dir . DIRECTORY_SEPARATOR . $handlerName . '.php';
20
        if (!is_file($path)) {
21
            throw new UnknownClassException('Class "' . $handlerName . '" was not found near to ' . $reflector->getName());
0 ignored issues
show
Bug introduced by
Consider using $reflector->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
22
        }
23
24
        $className = $reflector->getNamespaceName() . '\\' . $handlerName;
25
        return new $className();
26
    }
27
}
28