JobResolver::addJob()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SfCod\QueueBundle\Service;
4
5
use SfCod\QueueBundle\Base\JobInterface;
6
use SfCod\QueueBundle\Base\JobResolverInterface;
7
use SfCod\QueueBundle\Exception\JobNotFoundException;
8
9
/**
10
 * Class JobResolver
11
 *
12
 * @author Virchenko Maksim <[email protected]>
13
 *
14
 * @package SfCod\QueueBundle\Service
15
 */
16
class JobResolver implements JobResolverInterface
17
{
18
    /**
19
     * @var JobInterface[]
20
     */
21
    private $jobs = [];
22
23
    /**
24
     * Resolve the given class.
25
     *
26
     * @param string $id
27
     *
28
     * @return JobInterface
29
     */
30
    public function resolve(string $id): JobInterface
31
    {
32
        if (isset($this->jobs[$id])) {
33
            return $this->jobs[$id];
34
        }
35
36
        throw new JobNotFoundException("Job handler '$id' not found.");
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     *
42
     * @param string $id
43
     * @param JobInterface $job
44
     */
45
    public function addJob(string $id, JobInterface $job)
46
    {
47
        $this->jobs[$id] = $job;
48
    }
49
}
50