Completed
Branch master (c0d8ef)
by Yaroslav
06:36
created

ClassMapBuilder::build()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 13
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 3
nc 4
nop 1
crap 3
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 Symfony\Component\DependencyInjection\ContainerBuilder;
14
15
/**
16
 * ClassMapBuilder builds a ClassMap from ContainerBuilder.
17
 * Since it makes no sense to have private services in ClassMap, ClassMapBuilder should be run
18
 * by a CompilerPass with type TYPE_REMOVE (after removing private services).
19
 *
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class ClassMapBuilder
23
{
24
    /**
25
     * @param ContainerBuilder $container
26
     *
27
     * @return array
28
     */
29 2
    public function build(ContainerBuilder $container)
30
    {
31 2
        $map = [];
32
33 2
        foreach ($container->getDefinitions() as $id => $definition) {
34 2
            $map[$id] = $definition->getClass();
35
        }
36
37 2
        foreach ($container->getAliases() as $id => $alias) {
38 1
            $map[$id] = $map[(string) $alias];
39
        }
40
41 2
        return $map;
42
    }
43
}
44