Test Failed
Pull Request — master (#96)
by
unknown
02:30
created

DoctrineMappingsCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
c 1
b 1
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

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
final class DoctrineMappingsCompilerPass implements CompilerPassInterface
17
{
18
    /**
19
     * Process Doctrine mappings based on gesdinet_jwt_refresh_token.refresh_token_entity config parameter.
20
     * If this parameter contains user-defined entity, RefreshToken will be registered as a mapped superclass, not as an
21
     * entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined entity.
22
     *
23
     * @param ContainerBuilder $container
24
     */
25
    public function process(ContainerBuilder $container)
26
    {
27
        $mappings = array(
28
            realpath(__DIR__.'/../../Resources/config/doctrine-orm') => 'Gesdinet\JWTRefreshTokenBundle\Entity',
29
        );
30
        $config = $container->getExtensionConfig('gesdinet_jwt_refresh_token')[0];
31
        if (isset($config['refresh_token_entity'])) {
32
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-superclass')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
33
        } else {
34
            $mappings[realpath(__DIR__.'/../../Resources/config/doctrine-entity')] = 'Gesdinet\JWTRefreshTokenBundle\Entity';
35
        }
36
37
        $pass = DoctrineOrmMappingsPass::createYamlMappingDriver($mappings);
38
        $pass->process($container);
39
    }
40
}
41