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.
Completed
Push — master ( e5e7e8...c8b9dd )
by
unknown
09:35 queued 03:34
created

SurfnetStepupExtension   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 9
dl 0
loc 149
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A defineLoas() 0 10 1
A configureLocaleCookieSettings() 0 15 1
A configureGatewayApiClient() 0 22 1
A configureSmsSecondFactorServices() 0 14 1
C load() 0 51 8
A configureLocaleSelectionWidget() 0 10 2
A configureSecondFactorTypeService() 0 6 2
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupBundle\DependencyInjection;
20
21
use GuzzleHttp\HandlerStack;
22
use GuzzleHttp\Middleware;
23
use Surfnet\StepupBundle\Value\Loa;
24
use Symfony\Component\Config\Definition\Processor;
25
use Symfony\Component\Config\FileLocator;
26
use Symfony\Component\DependencyInjection\ContainerBuilder;
27
use Symfony\Component\DependencyInjection\Definition;
28
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
29
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
30
use Symfony\Component\DependencyInjection\Reference;
31
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
32
33
class SurfnetStepupExtension extends Extension
34
{
35
    public function load(array $config, ContainerBuilder $container)
36
    {
37
        $processor = new Processor();
38
        $config = $processor->processConfiguration(new Configuration(), $config);
39
40
        $container->setParameter('logging.application_name', $config['logging']['application_name']);
41
42
        $loader = new YamlFileLoader(
43
            $container,
44
            new FileLocator(__DIR__ . '/../Resources/config')
45
        );
46
        $loader->load('services.yml');
47
48
        if (isset($config['loa_definition']) && $config['loa_definition']['enabled']) {
49
            $this->defineLoas($config['loa_definition'], $container);
50
        } else {
51
            $container->removeDefinition('surfnet_stepup.service.loa_resolution');
52
        }
53
54
        if ($config['sms']['enabled'] === false) {
55
            $container->removeDefinition('surfnet_stepup.service.sms_second_factor');
56
            $container->removeDefinition('surfnet_stepup.service.challenge_handler');
57
            $container->removeDefinition('surfnet_stepup.service.sms_second_factor');
58
        } else {
59
            $this->configureSmsSecondFactorServices($config, $container);
60
61
            if (!$config['gateway_api']['enabled'] && $config['sms']['service'] === Configuration::DEFAULT_SMS_SERVICE) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
62
                throw new RuntimeException(
63
                    'The gateway API is not enabled and no replacement SMS service is configured'
64
                );
65
            }
66
        }
67
68
        if ($config['gateway_api']['enabled']) {
69
            $this->configureGatewayApiClient($config, $container);
70
        } else {
71
            // Remove the Gateway API SMS service and its Guzzle client.
72
            $container->removeDefinition('surfnet_stepup.service.gateway_api_sms');
73
            $container->removeDefinition('surfnet_stepup.guzzle.gateway_api');
74
        }
75
76
        if ($config['locale_cookie']['enabled']) {
77
            $this->configureLocaleCookieSettings($config, $container);
78
        } else {
79
            $container->removeDefinition('surfnet_stepup.locale_cookie_helper');
80
            $container->removeDefinition('surfnet_stepup.locale_cookie_settings');
81
        }
82
83
        $this->configureLocaleSelectionWidget($config, $container);
84
        $this->configureSecondFactorTypeService($config, $container);
85
    }
86
87
    private function defineLoas(array $loaDefinitions, ContainerBuilder $container)
88
    {
89
        $loaService = $container->getDefinition('surfnet_stepup.service.loa_resolution');
90
91
        $loa1 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_1, $loaDefinitions['loa1']]);
92
        $loa2 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_2, $loaDefinitions['loa2']]);
93
        $loa3 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_3, $loaDefinitions['loa3']]);
94
95
        $loaService->addArgument([$loa1, $loa2, $loa3]);
96
    }
97
98
    /**
99
     * @param array            $config
100
     * @param ContainerBuilder $container
101
     */
102
    private function configureLocaleCookieSettings(array $config, ContainerBuilder $container)
103
    {
104
        $container->getDefinition('surfnet_stepup.locale_cookie_settings')
105
            ->setArguments(
106
                [
107
                    $config['locale_cookie']['name'],
108
                    null,
109
                    $config['locale_cookie']['expire'],
110
                    $config['locale_cookie']['path'],
111
                    $config['locale_cookie']['domain'],
112
                    $config['locale_cookie']['secure'],
113
                    $config['locale_cookie']['http_only'],
114
                ]
115
            );
116
    }
117
118
    /**
119
     * @param array            $config
120
     * @param ContainerBuilder $container
121
     */
122
    private function configureGatewayApiClient(array $config, ContainerBuilder $container)
123
    {
124
        $handlerStack = $container->getDefinition('surfnet_stepup.guzzle.handler_stack');
125
126
        // Configure the Gateway API SMS service's Guzzle client.
127
        $gatewayGuzzleOptions = [
128
            'base_uri' => $config['gateway_api']['url'],
129
            'auth'    => [
130
                $config['gateway_api']['credentials']['username'],
131
                $config['gateway_api']['credentials']['password'],
132
                'basic'
133
            ],
134
            'headers' => [
135
                'Accept' => 'application/json'
136
            ],
137
            'handler' => $handlerStack,
138
            'http_errors' => false
139
        ];
140
141
        $gatewayGuzzle = $container->getDefinition('surfnet_stepup.guzzle.gateway_api');
142
        $gatewayGuzzle->replaceArgument(0, $gatewayGuzzleOptions);
143
    }
144
145
    /**
146
     * @param array            $config
147
     * @param ContainerBuilder $container
148
     */
149
    private function configureSmsSecondFactorServices(array $config, ContainerBuilder $container)
150
    {
151
        $smsSecondFactorService = $container->getDefinition('surfnet_stepup.service.sms_second_factor');
152
        $smsSecondFactorService->replaceArgument(2, $config['sms']['originator']);
153
154
        $container
155
            ->getDefinition('surfnet_stepup.service.challenge_handler')
156
            ->replaceArgument(2, $config['sms']['otp_expiry_interval'])
157
            ->replaceArgument(3, $config['sms']['maximum_otp_requests']);
158
159
        $container
160
            ->getDefinition('surfnet_stepup.service.sms_second_factor')
161
            ->replaceArgument(0, new Reference($config['sms']['service']));
162
    }
163
164
    private function configureLocaleSelectionWidget(array $loaDefinitions, ContainerBuilder $container)
0 ignored issues
show
Unused Code introduced by
The parameter $loaDefinitions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
    {
166
        if ($container->hasParameter('locales')) {
167
            $container->getDefinition('surfnet_stepup.form.choice_list.locales')
168
                ->replaceArgument(0, $container->getParameter('locales'));
169
        } else {
170
            $container->removeDefinition('surfnet_stepup.form.choice_list.locales');
171
            $container->removeDefinition('surfnet_stepup.form.switch_locale');
172
        }
173
    }
174
175
    private function configureSecondFactorTypeService(array $loaDefinitions, ContainerBuilder $container)
0 ignored issues
show
Unused Code introduced by
The parameter $loaDefinitions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177
        if (!$container->hasParameter('enabled_generic_second_factors')) {
178
            $container->removeDefinition('surfnet_stepup.service.second_factor_type');
179
        }
180
    }
181
}
182