Completed
Pull Request — master (#24)
by Wachter
02:13
created

TaskHandlerFactory::getHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\Handler;
13
14
use Task\Handler\TaskHandlerFactoryInterface;
15
use Task\Handler\TaskHandlerInterface;
16
use Task\Handler\TaskHandlerNotExistsException;
17
18
/**
19
 * Uses symfony container for collecting handler.
20
 */
21
class TaskHandlerFactory implements TaskHandlerFactoryInterface
22
{
23
    /**
24
     * @var TaskHandlerInterface[]
25
     */
26
    private $handler = [];
27
28
    /**
29
     * @param array $handler
30
     */
31 17
    public function __construct(array $handler)
32
    {
33 17
        $this->handler = $handler;
34 17
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 10
    public function create($className)
40
    {
41 10
        if (!array_key_exists($className, $this->handler)) {
42 3
            throw new TaskHandlerNotExistsException($className);
43
        }
44
45 7
        return $this->handler[$className];
46
    }
47
48
    /**
49
     * Returns all known handler.
50
     *
51
     * @return TaskHandlerInterface[]
52
     */
53
    public function getHandler()
54
    {
55
        return $this->handler;
56
    }
57
}
58