OsLabSecurityApiExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 41
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 10 1
B remapParametersNamespaces() 0 17 6
1
<?php
2
3
/*
4
 * This file is part of the OsLabSecurityApiBundle package.
5
 *
6
 * (c) OsLab <https://github.com/OsLab>
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 OsLab\SecurityApiBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
19
/**
20
 * Class load bundle extension.
21
 *
22
 * @author Michael COULLERET <[email protected]>
23
 * @author Florent DESPIERRES <[email protected]>
24
 */
25
class OsLabSecurityApiExtension extends Extension
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function load(array $configs, ContainerBuilder $container)
31
    {
32 3
        $configuration = new Configuration();
33 3
        $config = $this->processConfiguration($configuration, $configs);
34
35 3
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36 3
        $loader->load('security.yml');
37
38 3
        $this->remapParametersNamespaces($config, $container, ['authentication' => 'oslab_security_api.authentication.%s']);
39 3
    }
40
41
    /**
42
     * Maps parameters to add them in container.
43
     *
44
     * @param array            $config     the global config of this bundle
45
     * @param ContainerBuilder $container  the container for dependency injection
46
     * @param array            $namespaces config namespaces to add as parameters in the container
47
     */
48
    protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
49
    {
50 3
        foreach ($namespaces as $namespace => $map) {
51
            if (isset($namespace) && strlen($namespace) > 0) {
52 3
                if (!array_key_exists($namespace, $config)) {
53 3
                    continue;
54 3
                }
55
                $namespaceConfig = $config[$namespace];
56
            } else {
57 3
                $namespaceConfig = $config;
58
            }
59
60
            foreach ($namespaceConfig as $name => $value) {
61
                $container->setParameter(sprintf($map, $name), $value);
62 3
            }
63 3
        }
64
    }
65
}
66