Test Failed
Pull Request — master (#62)
by
unknown
05:03
created

GesdinetJWTRefreshTokenExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 48.21 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 6
dl 27
loc 56
ccs 12
cts 14
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 27 50 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\DependencyInjection\Definition;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
use Symfony\Component\DependencyInjection\Loader;
19
use Gesdinet\JWTRefreshTokenBundle\Events;
20
21
/**
22
 * This is the class that loads and manages your bundle configuration.
23
 *
24
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
25
 */
26
class GesdinetJWTRefreshTokenExtension extends Extension
27
{
28
    /**
29 1
     * {@inheritdoc}
30
     */
31 1
    public function load(array $configs, ContainerBuilder $container)
32 1
    {
33
        $configuration = new Configuration();
34 1
        $config = $this->processConfiguration($configuration, $configs);
35 1
36
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
37 1
        $loader->load('services.yml');
38 1
39 1
        $container->setParameter('gesdinet_jwt_refresh_token.ttl', $config['ttl']);
40 1
        $container->setParameter('gesdinet_jwt_refresh_token.ttl_update', $config['ttl_update']);
41
        $container->setParameter('gesdinet_jwt_refresh_token.security.firewall', $config['firewall']);
42
        $container->setParameter('gesdinet_jwt_refresh_token.user_provider', $config['user_provider']);
43 1
44
        //if refresh_token_entity has not be defined in config, we don't want to erase base value
45
        if (isset($config['refresh_token_entity'])) {
46
            $container->setParameter('gesdinet.jwtrefreshtoken.refresh_token.class', $config['refresh_token_entity']);
47 1
        }
48 1
49
        $container->setParameter('gesdinet.jwtrefreshtoken.entity_manager.id', $config['entity_manager']);
50
51 View Code Duplication
        if($config['methods']['request_body']['enabled']){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenExtractor\RequestBodyTokenExtractorEventListener::class, [$config['methods']['request_body']['name']]);
53
            $definition->addTag('kernel.event_listener', ['event' => Events::GET_TOKEN_REQUEST, 'method' => 'onGetToken']);
54
            $container->setDefinition('gesdinet_jwt_refresh_token.extractor.request_body', $definition);
55
56
            $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenSetter\ResponseBodyTokenSetterEventListener::class, [$config['methods']['request_body']['name']]);
57
            $definition->addTag('kernel.event_listener', ['event' => Events::ADD_TOKEN_RESPONSE, 'method' => 'onAddToken']);
58
            $container->setDefinition('gesdinet_jwt_refresh_token.setter.response_body', $definition);
59
        }
60
61 View Code Duplication
        if($config['methods']['request_header']['enabled']){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
            $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenExtractor\RequestHeaderTokenExtractorEventListener::class, [$config['methods']['request_header']['name']]);
63
            $definition->addTag('kernel.event_listener', ['event' => Events::GET_TOKEN_REQUEST, 'method' => 'onGetToken']);
64
            $container->setDefinition('gesdinet_jwt_refresh_token.extractor.request_header', $definition);
65
66
             $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenSetter\ResponseHeaderTokenSetterEventListener::class, [$config['methods']['request_header']['name']]);
67
            $definition->addTag('kernel.event_listener', ['event' => Events::ADD_TOKEN_RESPONSE, 'method' => 'onAddToken']);
68
            $container->setDefinition('gesdinet_jwt_refresh_token.setter.response_header', $definition);
69
        }
70
71 View Code Duplication
        if($config['methods']['cookie']['enabled']){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
            $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenExtractor\RequestCookieTokenExtractorEventListener::class, [$config['methods']['cookie']['name']]);
73
            $definition->addTag('kernel.event_listener', ['event' => Events::GET_TOKEN_REQUEST, 'method' => 'onGetToken']);
74
            $container->setDefinition('gesdinet_jwt_refresh_token.extractor.cookie', $definition);
75
76
            $definition = new Definition(\Gesdinet\JWTRefreshTokenBundle\EventListener\TokenSetter\ResponseCookieTokenSetterEventListener::class, [$config['methods']['cookie']['name'], $config['ttl']]);
77
            $definition->addTag('kernel.event_listener', ['event' => Events::ADD_TOKEN_RESPONSE, 'method' => 'onAddToken']);
78
            $container->setDefinition('gesdinet_jwt_refresh_token.setter.cookie', $definition);
79
        }
80
    }
81
}
82