HappyrGoogleSiteAuthenticatorExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 8
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 26 2
1
<?php
2
3
namespace Happyr\GoogleSiteAuthenticatorBundle\DependencyInjection;
4
5
use Happyr\GoogleSiteAuthenticatorBundle\Model\TokenConfig;
6
use Happyr\GoogleSiteAuthenticatorBundle\Service\ClientProvider;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ChildDefinition;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\DefinitionDecorator;
11
use Symfony\Component\DependencyInjection\Loader;
12
use Symfony\Component\DependencyInjection\Reference;
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
15
class HappyrGoogleSiteAuthenticatorExtension extends Extension
16
{
17
    /**
18
     * @param array            $configs
19 2
     * @param ContainerBuilder $container
20
     */
21 2
    public function load(array $configs, ContainerBuilder $container)
22 2
    {
23
        $configuration = new Configuration();
24 2
        $config = $this->processConfiguration($configuration, $configs);
25 2
26
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27
        $loader->load('services.yml');
28 2
29 2
        // Configure the correct PSR-6 cache
30
        $clientProvider = $container->getDefinition(ClientProvider::class);
31
        $clientProvider->replaceArgument(1, new Reference($config['cache_service']));
32 2
33 2
        // Configure TokenConfig
34
        $definition = $container->getDefinition(TokenConfig::class);
35
        $definition->replaceArgument(0, $config['tokens']);
36 2
37 2
        // make sure we shortcut the service name
38 2
        $decorator = new ChildDefinition('happyr.google_site_authenticator.client');
39 2
        foreach ($config['tokens'] as $name => $tokenConfig) {
40
            $service = $container->setDefinition('google.client.'.$name, $decorator);
41
            $service->replaceArgument(0, $name);
42
        }
43 2
44 2
        // set an alias for happyr.google_site_authenticator.client
45
        $container->setAlias('google.client', 'happyr.google_site_authenticator.client');
46
    }
47
}
48