Passed
Push — master ( d98237...ada1ad )
by Gerrit
13:03
created

RDMCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findDoctrineConnectionName() 0 12 3
A process() 0 7 1
1
<?php
2
/**
3
 * Copyright (C) 2019 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\RDMBundle\DependencyInjection;
14
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Alias;
18
19
final class RDMCompilerPass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        $container->setAlias(
24
            'addiks_rdm.doctrine.orm.configuration', 
25
            new Alias(sprintf(
26
                'doctrine.orm.%s_configuration',
27
                $this->findDoctrineConnectionName($container) ?? 'default'
28
            ))
29
        );
30
    }
31
    
32
    private function findDoctrineConnectionName(ContainerBuilder $container): ?string
33
    {
34
        /** @var array<int, array<string, mixed>> $doctrineConfigs */
35
        $doctrineConfigs = $container->getExtensionConfig('doctrine');
36
        
37
        foreach ($doctrineConfigs as $doctrineConfig) {
38
            foreach ($doctrineConfig['dbal']['connections'] ?? [] as $name => $connection) {
39
                return $name;
40
            }
41
        }
42
        
43
        return null;
44
    }
45
    
46
}
47