Completed
Pull Request — master (#108)
by Julián
26:17 queued 06:59
created

getObjectManager()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/*
4
 * This file is part of the GesdinetJWTRefreshTokenBundle package.
5
 *
6
 * (c) Gesdinet <http://www.gesdinet.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17
use Symfony\Component\DependencyInjection\Loader;
18
19
/**
20
 * This is the class that loads and manages your bundle configuration.
21
 *
22
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
23
 */
24
class GesdinetJWTRefreshTokenExtension extends Extension
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function load(array $configs, ContainerBuilder $container)
30
    {
31 1
        $configuration = new Configuration();
32 1
        $config = $this->processConfiguration($configuration, $configs);
33
34 1
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35 1
        $loader->load('services.yml');
36
37 1
        $container->setParameter('gesdinet_jwt_refresh_token.ttl', $config['ttl']);
38 1
        $container->setParameter('gesdinet_jwt_refresh_token.ttl_update', $config['ttl_update']);
39 1
        $container->setParameter('gesdinet_jwt_refresh_token.security.firewall', $config['firewall']);
40 1
        $container->setParameter('gesdinet_jwt_refresh_token.user_provider', $config['user_provider']);
41
        $container->setParameter('gesdinet_jwt_refresh_token.user_identity_field', $config['user_identity_field']);
42
43 1
        $refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken';
44
        $objectManager = 'doctrine.orm.entity_manager';
45
46
        if ('mongodb' === strtolower($config['manager_type'])) {
47 1
            $refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken';
48 1
            $objectManager = 'doctrine_mongodb.odm.document_manager';
49
        }
50
51
        if (null !== $this->getRefreshTokenClass($config)) {
52
            $refreshTokenClass = $this->getRefreshTokenClass($config);
53
        }
54
55
        if (null !== $this->getObjectManager($config)) {
56
            $objectManager = $this->getObjectManager($config);
57
        }
58
59
        $container->setParameter('gesdinet.jwtrefreshtoken.refresh_token.class', $refreshTokenClass);
60
        $container->setParameter('gesdinet.jwtrefreshtoken.object_manager.id', $objectManager);
61
    }
62
63
    /**
64
     * Get refresh token class from configuration.
65
     *
66
     * Supports deprecated configuration
67
     *
68
     * @param array $config
69
     *
70
     * @return string|null
71
     */
72
    protected function getRefreshTokenClass(array $config)
73
    {
74
        if (isset($config['refresh_token_class'])) {
75
            return $config['refresh_token_class'];
76
        }
77
78
        return $config['refresh_token_entity'] ?: null;
79
    }
80
81
    /**
82
     * Get object manager from configuration.
83
     *
84
     * Supports deprecated configuration
85
     *
86
     * @param array $config
87
     *
88
     * @return string|null
89
     */
90
    protected function getObjectManager(array $config)
91
    {
92
        if (isset($config['object_manager'])) {
93
            return $config['object_manager'];
94
        }
95
96
        return $objectManager = $config['entity_manager'] ?: null;
0 ignored issues
show
Unused Code introduced by
$objectManager is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
    }
98
}
99