GmRedmineUserProviderExtension   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 6
dl 0
loc 70
ccs 29
cts 29
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 10 1
A registerParameters() 0 23 3
B loadServices() 0 17 5
1
<?php
2
/**
3
 * File part of the Redmine User Provider bundle
4
 *
5
 * @category  SymfonyBundle
6
 * @package   GMaissa.RedmineUserProviderBundle
7
 * @author    Guillaume Maïssa <[email protected]>
8
 * @copyright 2017 Guillaume Maïssa
9
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
10
 */
11
12
namespace GMaissa\RedmineUserProviderBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Processor;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
/**
21
 * Infrastructure UserBundle Dependency Injection Class
22
 */
23
class GmRedmineUserProviderExtension extends Extension
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 10
    public function load(array $configs, ContainerBuilder $container)
29
    {
30 10
        $processor     = new Processor();
31 10
        $configuration = new Configuration();
32 10
        $config        = $processor->processConfiguration($configuration, $configs);
33
34 10
        $this->registerParameters($container, $config);
35
36 9
        $this->loadServices($container, $config);
37 9
    }
38
39
    /**
40
     * Set parameters from bundle configuration
41
     *
42
     * @param ContainerBuilder $container
43
     * @param array            $config
44
     */
45 10
    private function registerParameters(ContainerBuilder $container, array $config)
46
    {
47 10
        $container->setParameter('gm_redmine_user_provider.redmine.url', $config['redmine']['url']);
48 10
        $container->setParameter(
49 10
            'gm_redmine_user_provider.redmine.allowed_domains',
50 10
            $config['redmine']['allowed_domains']
51
        );
52 10
        if (isset($config['user_class'])) {
53 10
            $reflection    = new \ReflectionClass($config['user_class']);
54 10
            $userInterface = '\Symfony\Component\Security\Core\User\UserInterface';
55 10
            if (!$reflection->implementsInterface($userInterface)) {
56 1
                throw new \InvalidArgumentException(
57
                    sprintf(
58 1
                        'The user class %s should implement interface "%s"',
59 1
                        $config['user_class'],
60
                        $userInterface
61
                    )
62
                );
63
            }
64
65 9
            $container->setParameter('gm_redmine_user_provider.user_class', $config['user_class']);
66
        }
67 9
    }
68
69
    /**
70
     * Load default and persistence services
71
     *
72
     * @param ContainerBuilder $container
73
     * @param array            $config
74
     */
75 9
    private function loadServices(ContainerBuilder $container, array $config)
76
    {
77 9
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
78
79
        // Load default services
80 9
        $loader->load('services.yml');
81
82
        // Load persistence services
83 9
        if (isset($config['persistence_driver']) && !is_null($config['persistence_driver'])) {
84 2
            $loader->load(sprintf('%s.yml', $config['persistence_driver']));
85
        }
86
87
        // services for FOS OAuth Server bundle
88 9
        if (isset($config['oauthserver_bridge']) && $config['oauthserver_bridge']) {
89 1
            $loader->load('oauthserver.yml');
90
        }
91 9
    }
92
}
93