ServiceRepositoryCompilerPass   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 2
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
final class ServiceRepositoryCompilerPass implements CompilerPassInterface
11
{
12
    const REPOSITORY_SERVICE_TAG = 'doctrine.repository_service';
13
14
    public function process(ContainerBuilder $container) : void
15
    {
16
        // when ORM is not enabled
17
        if (! $container->hasDefinition('doctrine.orm.container_repository_factory')) {
18
            return;
19
        }
20
21
        $locatorDef = $container->getDefinition('doctrine.orm.container_repository_factory');
22
23
        $repoServiceIds = array_keys($container->findTaggedServiceIds(self::REPOSITORY_SERVICE_TAG));
24
25
        $repoReferences = array_map(static function ($id) {
26
            return new Reference($id);
27
        }, $repoServiceIds);
28
29
        $ref = ServiceLocatorTagPass::register($container, array_combine($repoServiceIds, $repoReferences));
30
        $locatorDef->replaceArgument(0, $ref);
31
    }
32
}
33