GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Pull Request — master (#91)
by
unknown
07:24
created

LexikPayboxExtension   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 111
Duplicated Lines 25.23 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 8
dl 28
loc 111
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 10 1
A processAccountsConfiguration() 0 18 3
A createTransportService() 0 9 1
A createRequestHandlerService() 14 14 1
A createRequestCancellationHandlerService() 14 14 1
A createResponseHandlerService() 0 16 1
A createDirecPlusRequestHandlerService() 0 18 1

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
namespace Lexik\Bundle\PayboxBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
use Symfony\Component\DependencyInjection\Loader;
11
12
/**
13
 * This is the class that loads and manages your bundle configuration
14
 *
15
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
16
 */
17
class LexikPayboxExtension extends Extension
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function load(array $configs, ContainerBuilder $container)
23
    {
24
        $configuration = new Configuration();
25
        $config = $this->processConfiguration($configuration, $configs);
26
27
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
28
        $loader->load('services.yml');
29
30
        $this->processAccountsConfiguration($config, $container);
31
    }
32
33
    private function processAccountsConfiguration(array $config, ContainerBuilder $container)
34
    {
35
        foreach ($config['accounts'] as $name => $options) {
36
            if (null === $options['public_key']) {
37
                $options['public_key'] = __DIR__ . '/../Resources/config/paybox_public_key.pem';
38
            }
39
40
            $options['parameters']['public_key'] = $options['public_key'];
41
42
            $this
43
                ->createTransportService($name, $options, $container)
44
                ->createRequestHandlerService($name, $options, $container)
45
                ->createRequestCancellationHandlerService($name, $options, $container)
46
                ->createResponseHandlerService($name, $options, $container)
47
                ->createDirecPlusRequestHandlerService($name, $options, $container)
48
            ;
49
        }
50
    }
51
52
    private function createTransportService($name, array $options, ContainerBuilder $container)
53
    {
54
        $client = new Definition($options['transport']);
55
56
        $clientServiceId = sprintf('lexik_paybox.transport.%s', $name);
57
        $container->setDefinition($clientServiceId, $client);
58
59
        return $this;
60
    }
61
62 View Code Duplication
    private function createRequestHandlerService($name, array $options, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
63
    {
64
        $client = new Definition($container->getParameterBag()->get('lexik_paybox.request_handler.class'));
65
66
        $client->addArgument($name);
67
        $client->addArgument($options['parameters']);
68
        $client->addArgument($options['servers']);
69
        $client->addArgument(new Reference('form.factory'));
70
71
        $clientServiceId = sprintf('lexik_paybox.request_handler.%s', $name);
72
        $container->setDefinition($clientServiceId, $client);
73
74
        return $this;
75
    }
76
77 View Code Duplication
    private function createRequestCancellationHandlerService($name, array $options, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
78
    {
79
        $client = new Definition($container->getParameterBag()->get('lexik_paybox.request_cancellation_handler.class'));
80
81
        $client->addArgument($name);
82
        $client->addArgument($options['parameters']);
83
        $client->addArgument($options['servers']);
84
        $client->addArgument(new Reference(sprintf('lexik_paybox.transport.%s', $name)));
85
86
        $clientServiceId = sprintf('lexik_paybox.request_cancellation_handler.%s', $name);
87
        $container->setDefinition($clientServiceId, $client);
88
89
        return $this;
90
    }
91
92
    private function createResponseHandlerService($name, array $options, ContainerBuilder $container)
93
    {
94
        $client = new Definition($container->getParameterBag()->get('lexik_paybox.response_handler.class'));
95
96
        $client->addArgument(new Reference('request_stack'));
97
        $client->addArgument(new Reference('logger'));
98
        $client->addArgument(new Reference('event_dispatcher'));
99
        $client->addArgument($options['parameters']);
100
101
        $client->addTag('monolog.logger', ['channel' => 'payment']);
102
103
        $clientServiceId = sprintf('lexik_paybox.response_handler.%s', $name);
104
        $container->setDefinition($clientServiceId, $client);
105
106
        return $this;
107
    }
108
109
    private function createDirecPlusRequestHandlerService($name, array $options, ContainerBuilder $container)
110
    {
111
        $client = new Definition($container->getParameterBag()->get('lexik_paybox.direc_plus.request_handler.class'));
112
113
        $client->addArgument($name);
114
        $client->addArgument($options['parameters']);
115
        $client->addArgument($options['servers']);
116
        $client->addArgument(new Reference('logger'));
117
        $client->addArgument(new Reference('event_dispatcher'));
118
        $client->addArgument(new Reference(sprintf('lexik_paybox.transport.%s', $name)));
119
120
        $client->addTag('monolog.logger', ['channel' => 'payment']);
121
122
        $clientServiceId = sprintf('lexik_paybox.direc_plus.request_handler.%s', $name);
123
        $container->setDefinition($clientServiceId, $client);
124
125
        return $this;
126
    }
127
}
128