Test Failed
Pull Request — master (#96)
by
unknown
08:52
created

DoctrineMappingsCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 2
1
<?php
2
3
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection\Compiler;
4
5
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Class DoctrineMappingsCompilerPass
11
 *
12
 * We can't add DoctrineOrmMappingsPass directly, because in GesdinetJWTRefreshTokenBundle->build we don't have current
13
 * bundle configuration yet.
14
 * This CompilerPass is effectively just a wrapper for DoctrineOrmMappingsPass, which passes mappings conditionally.
15
 *
16
 * @package Gesdinet\JWTRefreshTokenBundle\DependencyInjection\Compiler
17
 */
18
final class DoctrineMappingsCompilerPass implements CompilerPassInterface
19
{
20
    /**
21
     * Process Doctrine mappings based on gesdinet_jwt_refresh_token.refresh_token_entity config parameter.
22
     * If this parameter contains user-defined entity, RefreshToken will be registered as a mapped superclass, not as an
23
     * entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined entity.
24
     *
25
     * @param ContainerBuilder $container
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        $mappings = array(
30
            realpath(__DIR__.'/../../Resources/config/doctrine-orm') => 'Gesdinet\JWTRefreshTokenBundle\Entity',
31
        );
32
        $config = $container->getExtensionConfig('gesdinet_jwt_refresh_token')[0];
33
        if (isset($config['refresh_token_entity'])) {
34
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-superclass')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
35
        } else {
36
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-entity')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
37
        }
38
39
        $pass = DoctrineOrmMappingsPass::createYamlMappingDriver($mappings);
40
        $pass->process($container);
41
    }
42
43
}
44