Completed
Pull Request — master (#15)
by Wachter
07:53
created

TaskHandlerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 8 2
1
<?php
2
3
namespace Task\TaskBundle\Handler;
4
5
use Symfony\Component\CssSelector\Parser\Handler\HandlerInterface;
6
use Task\Handler\TaskHandlerFactoryInterface;
7
use Task\Handler\TaskHandlerNotExistsException;
8
9
class TaskHandlerFactory implements TaskHandlerFactoryInterface
10
{
11
    /**
12
     * @var HandlerInterface[]
13
     */
14
    private $handler = [];
15
16
    public function __construct(array $handler)
17
    {
18
        $this->handler = $handler;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function create($className)
25
    {
26
        if (!array_key_exists($className, $this->handler)) {
27
            throw new TaskHandlerNotExistsException($className);
28
        }
29
30
        return $this->handler[$className];
31
    }
32
}
33