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

TaskHandlerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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