Completed
Pull Request — master (#24)
by Wachter
03:36
created

TaskHandlerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 37
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 8 2
A getHandlers() 0 4 1
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