Completed
Push — master ( c08683...8607fa )
by Adam
16:41
created

SimpleHandlerFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 48
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B get() 0 17 5
A getHandler() 0 4 2
1
<?php
2
3
namespace Equip\Queue\Handler;
4
5
use Equip\Queue\Exception\HandlerException;
6
7
class SimpleHandlerFactory implements HandlerFactoryInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $handlers;
13
14
    /**
15
     * @param array $handlers
16
     */
17 4
    public function __construct(array $handlers = [])
18
    {
19 4
        $this->handlers = $handlers;
20 4
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25 4
    public function get($name)
26
    {
27 4
        $handler = $this->getHandler($name);
28 4
        if (!$handler) {
29 1
            throw HandlerException::notFound($name);
30
        }
31
32 3
        if (is_string($handler) && class_exists($handler)) {
33 1
            $handler = new $handler;
34 1
        }
35
36 3
        if (is_callable($handler)) {
37 2
            return $handler;
38
        }
39
40 1
        throw HandlerException::invalidHandler($name);
41
    }
42
43
    /**
44
     * Get the handler
45
     *
46
     * @param string $name
47
     *
48
     * @return mixed|null
49
     */
50 4
    private function getHandler($name)
51
    {
52 4
        return isset($this->handlers[$name]) ? $this->handlers[$name] : null;
53
    }
54
}
55