TwoMartensCoreExtension::load()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 57
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 2 Features 4
Metric Value
c 7
b 2
f 4
dl 0
loc 57
rs 8.7433
cc 6
eloc 34
nc 10
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
 * This file is part of the 2martens Web Platform.
4
 *
5
 * (c) Jim Martens <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace TwoMartens\Bundle\CoreBundle\DependencyInjection;
12
13
use Symfony\Component\Config\FileLocator;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Extension\Extension;
16
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
17
18
/**
19
 * Container extension for TwoMartensCoreBundle.
20
 *
21
 * @author Jim Martens <[email protected]>
22
 */
23
class TwoMartensCoreExtension extends Extension
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(array $configs, ContainerBuilder $container)
29
    {
30
        $loader = new YamlFileLoader(
31
            $container,
32
            new FileLocator(__DIR__.'/../Resources/config')
33
        );
34
        $loader->load('services.yml');
35
36
        // TODO replace with semantic configuration
37
        $config = [
38
            'db_driver' => 'mongodb'
39
        ];
40
        $container->setParameter('twomartens.core.storage', $config['db_driver']);
41
42
        if ('custom' !== $config['db_driver']) {
43
            $loader->load(sprintf('%s.yml', $config['db_driver']));
44
            $container->setParameter('twomartens.core.backend_type_' . $config['db_driver'], true);
45
        }
46
47
        switch ($config['db_driver']) {
48
            case 'orm':
49
                $container->getDefinition('twomartens.core.group_listener')
50
                    ->addTag(
51
                        'doctrine.event_subscriber',
52
                        [
53
                            'priority' => 10
54
                        ]
55
                    );
56
                break;
57
58
            case 'mongodb':
59
                $container->getDefinition('twomartens.core.group_listener')
60
                    ->addTag(
61
                        'doctrine_mongodb.odm.event_subscriber',
62
                        [
63
                            'priority' => 10
64
                        ]
65
                    );
66
                break;
67
68
            case 'couchdb':
69
                $container->getDefinition('twomartens.core.group_listener')
70
                    ->addTag(
71
                        'doctrine_couchdb.event_subscriber',
72
                        [
73
                            'priority' => 10
74
                        ]
75
                    );
76
                break;
77
78
            case 'propel':
79
                break;
80
81
            default:
82
                break;
83
        }
84
    }
85
}
86