Completed
Push — 2.0 ( 0c16d7...3ed48a )
by Peter
04:05
created

AnimeDbAniDbBrowserExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 3
c 6
b 0
f 0
lcom 0
cbo 6
dl 0
loc 37
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 16 1
A getRealServiceName() 0 8 2
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AniDbBrowserBundle\DependencyInjection;
10
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\Config\FileLocator;
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
use Symfony\Component\DependencyInjection\Loader;
15
16
class AnimeDbAniDbBrowserExtension extends Extension
17
{
18
    /**
19
     * @param array $configs
20
     * @param ContainerBuilder $container
21
     */
22 11
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 11
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25 11
        $loader->load('parameters.yml');
26 11
        $loader->load('services.yml');
27
28 11
        $config = $this->processConfiguration(new Configuration(), $configs);
29
30
        $container
31 4
            ->getDefinition('anime_db.ani_db.browser.client.guzzle.request_configurator')
32 4
            ->addMethodCall('setAppVersion', [$config['app']['version']])
33 4
            ->addMethodCall('setAppClient', [$config['app']['client']])
34 4
            ->addMethodCall('setAppCode', [$config['app']['code']]);
35
36 4
        $container->setAlias('anime_db.ani_db.browser.client', $this->getRealServiceName($config['client']));
37 4
    }
38
39
    /**
40
     * @param string $name
41
     *
42
     * @return string
43
     */
44 4
    protected function getRealServiceName($name)
45
    {
46 4
        if (in_array($name, ['cache', 'guzzle'])) {
47 3
            return 'anime_db.ani_db.browser.client.'.$name;
48
        }
49
50 1
        return $name;
51
    }
52
}
53