Test Failed
Branch master (cd46ea)
by Hirofumi
02:16
created

JobRunnerRegistry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Shippinno\Job\Application\Job;
4
5
use Shippinno\Job\Domain\Model\JobNotRegisteredException;
6
7
class JobRunnerRegistry
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $jobRunners = [];
13
14
    /**
15
     * @param array $jobRunners
16
     */
17
    public function register(array $jobRunners): void
18
    {
19
        foreach ($jobRunners as $jobName => $jobRunner) {
20
            $this->jobRunners[$jobName] = $jobRunner;
21
        }
22
    }
23
24
    /**
25
     * @param string $jobName
26
     * @return JobRunner
27
     * @throws JobNotRegisteredException
28
     */
29
    public function get(string $jobName): JobRunner
30
    {
31
        if (!isset($this->jobRunners[$jobName])) {
32
            throw new JobNotRegisteredException;
33
        }
34
35
        return $this->jobRunners[$jobName];
36
    }
37
}
38