Test Failed
Push — master ( 575e5f...bb3910 )
by Hirofumi
02:01
created

JobRunnerRegistry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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