Completed
Pull Request — master (#1)
by Jim
08:57
created

Registry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Jarobe\TaskRunner\Hydrator;
4
5
use Jarobe\TaskRunner\Exception\TaskException;
6
7
class Registry implements RegistryInterface
8
{
9
    private $discoverer;
10
11
    public function __construct(DiscoveryInterface $taskDiscoverer)
12
    {
13
        $this->discoverer = $taskDiscoverer;
14
    }
15
16
    /**
17
     * Returns the FQCN for a Task name
18
     *
19
     * @param $name
20
     * @return string
21
     * @throws TaskException
22
     */
23
    public function getClassByName($name)
24
    {
25
        $taskClasses = $this->discoverer->getTasks();
26
27
        if (!isset($taskClasses[$name])) {
28
            throw new TaskException(
29
                sprintf("No Task found for name %s. You may need to add the Task to the Registry", $name)
30
            );
31
        }
32
33
        return $taskClasses[$name];
34
    }
35
}
36
37