ContextRegistry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A getClass() 0 11 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