Completed
Push — master ( e8b6fd...0f4d98 )
by Wachter
05:21 queued 01:37
created

TaskHandlerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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 $handlers = [];
27
28
    /**
29
     * @param TaskHandlerInterface[] $handlers
30
     */
31 17
    public function __construct(array $handlers)
32
    {
33 17
        $this->handlers = $handlers;
34 17
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 10
    public function create($className)
40
    {
41 10
        if (!array_key_exists($className, $this->handlers)) {
42 3
            throw new TaskHandlerNotExistsException($className);
43
        }
44
45 7
        return $this->handlers[$className];
46
    }
47
48
    /**
49
     * Returns all known handler.
50
     *
51
     * @return TaskHandlerInterface[]
52
     */
53
    public function getHandlers()
54
    {
55
        return $this->handlers;
56
    }
57
}
58