DriverFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDriverForTask() 0 12 3
1
<?php
2
3
namespace Jarobe\TaskRunnerBundle\Driver\Factory;
4
5
use Jarobe\TaskRunnerBundle\Driver\TaskDriverInterface;
6
use Jarobe\TaskRunnerBundle\Exception\TaskException;
7
use Jarobe\TaskRunnerBundle\TaskType\TaskTypeInterface;
8
9
class DriverFactory
10
{
11
    /** @var TaskDriverInterface[] */
12
    private $taskDrivers;
13
14
    public function __construct(array $taskDrivers)
15
    {
16
        $this->taskDrivers = $taskDrivers;
17
    }
18
19
    /**
20
     * @param TaskTypeInterface $task
21
     * @return TaskDriverInterface
22
     * @throws TaskException
23
     */
24
    public function getDriverForTask(TaskTypeInterface $task)
25
    {
26
        $class = get_class($task);
27
28
        foreach ($this->taskDrivers as $taskDriver) {
29
            if ($taskDriver->supportsClass($class)) {
30
                return $taskDriver;
31
            }
32
        }
33
34
        throw new TaskException("No driver found for ".$class);
35
    }
36
}
37