ContextRegistry::add()   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
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ContextServiceExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace FriendsOfBehat\ContextServiceExtension\Context;
15
16
/**
17
 * @internal
18
 */
19
final class ContextRegistry
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $registry;
25
26
    /**
27
     * @param string $serviceId
28
     * @param string $serviceClass
29
     */
30
    public function add(string $serviceId, string $serviceClass): void
31
    {
32
        $this->registry[$serviceId] = $serviceClass;
33
    }
34
35
    /**
36
     * @param string $serviceId
37
     *
38
     * @return string
39
     *
40
     * @throws \InvalidArgumentException
41
     */
42
    public function getClass(string $serviceId): string
43
    {
44
        if (!isset($this->registry[$serviceId])) {
45
            throw new \InvalidArgumentException(sprintf(
46
                'Could not find class for service with id "%s".',
47
                $serviceId
48
            ));
49
        }
50
51
        return $this->registry[$serviceId];
52
    }
53
}
54