Bus   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 6 1
A handlersNamespace() 0 4 1
A resolveHandler() 0 9 2
A getClassNameFromSerial() 0 11 2
1
<?php
2
3
namespace R\Hive\Concrete\Commands;
4
5
use R\Hive\Concrete\Exceptions\NoSupportedHandlerFoundException;
6
use R\Hive\Contracts\Commands\BusInterface;
7
use R\Hive\Contracts\Commands\CommandInterface;
8
9
class Bus implements BusInterface
10
{
11
    public function execute(CommandInterface $command)
12
    {
13
        return $this
14
            ->resolveHandler($command->serial())
15
            ->execute($command);
16
    }
17
18
    public function handlersNamespace()
19
    {
20
        return 'App\Lib\Commands\Handlers';
21
    }
22
23
    public function resolveHandler($serial)
24
    {
25
        $class = $this->getClassNameFromSerial($serial);
26
        if (class_exists($class)) {
27
            return new $class();
28
        }
29
30
        throw new NoSupportedHandlerFoundException($serial);
31
    }
32
33
    protected function getClassNameFromSerial($serial)
34
    {
35
        $parts = explode('_', $serial);
36
        $class = '';
37
38
        foreach ($parts as $part) {
39
            $class .= ucfirst($part);
40
        }
41
42
        return $this->handlersNamespace().'\\'.$class.'Handler';
43
    }
44
}
45