Passed
Pull Request — master (#151)
by
unknown
02:46
created

ChainManagerRegistryPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
1
<?php
2
3
4
namespace Zenstruck\Foundry\Bundle\DependencyInjection;
5
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Zenstruck\Foundry\ChainManagerRegistry;
11
12
class ChainManagerRegistryPass implements CompilerPassInterface
13
{
14
    public function process(ContainerBuilder $container)
15
    {
16
        $managerRegistries = [];
17
18
        if ($container->hasDefinition('doctrine')) {
19
            $managerRegistries[] = new Reference('doctrine');
20
        }
21
22
        if ($container->hasDefinition('doctrine_mongodb')) {
23
            $managerRegistries[] = new Reference('doctrine_mongodb');
24
        }
25
26
        if (count($managerRegistries) === 0) {
27
            throw new \LogicException('Neither doctrine/orm nor doctrine/mongo-odm are present.');
28
        }
29
30
        $container->getDefinition(ChainManagerRegistry::class)
31
            ->setArgument('$managerRegistries', $managerRegistries);
32
    }
33
}
34