Completed
Push — master ( 531aca...edc713 )
by Kamil
04:19
created

ContextRegistry   A

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