ClassMap::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\DependencyInjection\Container;
12
13
use Yarhon\RouteGuardBundle\Exception\InvalidArgumentException;
14
15
/**
16
 * ClassMap is responsible for storing DI container class map: service id => class name.
17
 * Since \Symfony\Component\DependencyInjection\ContainerInterface doesn't allow to get actual service class
18
 * without instantiating it, we need ClassMap for the code that needs to be able to resolve service class by its id.
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class ClassMap implements ClassMapInterface
23
{
24
    /**
25
     * @var string[]
26
     */
27
    private $map;
28
29
    /**
30
     * @param array $map
31
     */
32 26
    public function __construct(array $map = [])
33
    {
34 26
        $this->map = $map;
35 26
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 26
    public function has($id)
41
    {
42 26
        return array_key_exists($id, $this->map);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 5
    public function get($id)
49
    {
50 5
        if (!$this->has($id)) {
51 1
            throw new InvalidArgumentException(sprintf('Service "%s" is not found.', $id));
52
        }
53
54 4
        return $this->map[$id];
55
    }
56
}
57