KuleuvenAuthenticationExtension::load()   C
last analyzed

Complexity

Conditions 7
Paths 27

Size

Total Lines 79
Code Lines 53

Duplication

Lines 10
Ratio 12.66 %

Importance

Changes 0
Metric Value
dl 10
loc 79
rs 6.5649
c 0
b 0
f 0
cc 7
eloc 53
nc 27
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\DependencyInjection;
4
5
use Kuleuven\AuthenticationBundle\Model\KuleuvenUser;
6
use Kuleuven\AuthenticationBundle\Security\KuleuvenUserToken;
7
use Kuleuven\AuthenticationBundle\Security\ShibbolethAuthenticationEntryPoint;
8
use Kuleuven\AuthenticationBundle\Security\ShibbolethAuthenticationListener;
9
use Kuleuven\AuthenticationBundle\Security\ShibbolethAuthenticationListenerFactory;
10
use Kuleuven\AuthenticationBundle\Security\ShibbolethAuthenticationProvider;
11
use Kuleuven\AuthenticationBundle\Service\LdapService;
12
use Kuleuven\AuthenticationBundle\Service\ShibbolethServiceProvider;
13
use Kuleuven\AuthenticationBundle\Service\ShibbolethUserProvider;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
use Symfony\Component\DependencyInjection\Loader;
20
21
class KuleuvenAuthenticationExtension extends Extension implements ExtensionInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load(array $configs, ContainerBuilder $container)
27
    {
28
        $this->addClassesToCompile([
29
            ShibbolethAuthenticationListenerFactory::class,
30
            ShibbolethAuthenticationEntryPoint::class,
31
            ShibbolethAuthenticationProvider::class,
32
            ShibbolethAuthenticationListener::class,
33
            ShibbolethServiceProvider::class,
34
            ShibbolethUserProvider::class,
35
            LdapService::class,
36
            KuleuvenUserToken::class,
37
            KuleuvenUser::class,
38
        ]);
39
40
        $configuration = new Configuration();
41
        $config = $this->processConfiguration($configuration, $configs);
42
43
        // Attribute definitions
44 View Code Duplication
        if (isset($config['authentication_attribute_definitions'])) {
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...
45
            $container->setParameter('authentication_attribute_definitions', $config['authentication_attribute_definitions']);
46
        } elseif (!$container->hasParameter('authentication_attribute_definitions')) {
47
            $container->setParameter('authentication_attribute_definitions', []);
48
        }
49
50
        // Attribute requirements
51
        $container->setParameter('authentication_attribute_requirements', $config['authentication_attribute_requirements']);
52
53
        // Attribute overwrites
54
        $container->setParameter('authentication_attribute_overwrites_enabled', $config['authentication_attribute_overwrites_enabled']);
55 View Code Duplication
        if (isset($config['authentication_attribute_overwrites'])) {
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...
56
            $container->setParameter('authentication_attribute_overwrites', $config['authentication_attribute_overwrites']);
57
        } elseif (!$container->hasParameter('authentication_attribute_overwrites')) {
58
            $container->setParameter('authentication_attribute_overwrites', []);
59
        }
60
61
        // Attribute LDAP overwrites
62
        $container->setParameter('authentication_attribute_ldap_enabled', $config['authentication_attribute_ldap_enabled']);
63
        $container->setParameter('authentication_attribute_ldap_filter', $config['authentication_attribute_ldap_filter']);
64
65
        // Attribute header overwrites
66
        $container->setParameter('authentication_attribute_headers_enabled', $config['authentication_attribute_headers_enabled']);
67
68
        // Shibboleth
69
        $container->setParameter('shibboleth_is_secured_handler', $config['shibboleth_is_secured_handler']);
70
        $container->setParameter('shibboleth_handler_path', $config['shibboleth_handler_path']);
71
        $container->setParameter('shibboleth_status_path', $config['shibboleth_status_path']);
72
        $container->setParameter('shibboleth_session_login_path', $config['shibboleth_session_login_path']);
73
        $container->setParameter('shibboleth_session_logout_path', $config['shibboleth_session_logout_path']);
74
        $container->setParameter('shibboleth_session_logout_target', $config['shibboleth_session_logout_target']);
75
        $container->setParameter('shibboleth_session_overview_path', $config['shibboleth_session_overview_path']);
76
        $container->setParameter('shibboleth_username_attribute', $config['shibboleth_username_attribute']);
77
        $container->setParameter('shibboleth_authenticated_attribute', $config['shibboleth_authenticated_attribute']);
78
        $container->setParameter('shibboleth_logout_url_attribute', $config['shibboleth_logout_url_attribute']);
79
        $container->setParameter('shibboleth_default_charset', $config['shibboleth_default_charset']);
80
81
        // LDAP
82
        $container->setParameter('ldap_rdn', $config['ldap_rdn']);
83
        if (!$container->hasParameter('ldap_rdn')) {
84
            throw new InvalidArgumentException('ldap_rdn parameter is required');
85
        }
86
        $container->setParameter('ldap_password', $config['ldap_password']);
87
        if (!$container->hasParameter('ldap_password')) {
88
            throw new InvalidArgumentException('ldap_password parameter is required');
89
        }
90
        $container->setParameter('ldap_base', $config['ldap_base']);
91
        $container->setParameter('ldap_domain', $config['ldap_domain']);
92
        $container->setParameter('ldap_port', $config['ldap_port']);
93
        $container->setParameter('ldap_encryption', $config['ldap_encryption']);
94
        $container->setParameter('ldap_referrals', $config['ldap_referrals']);
95
        $container->setParameter('ldap_version', $config['ldap_version']);
96
        $container->setParameter('ldap_debug', $config['ldap_debug']);
97
98
        // Person Data API
99
        $container->setParameter('person_data_api_url', $config['person_data_api_url']);
100
101
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
102
        $loader->load('services.yml');
103
104
    }
105
}
106