Completed
Pull Request — master (#15)
by Wachter
15:35 queued 05:39
created

TaskHandlerFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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