Completed
Push — master ( 4fe364...f1a872 )
by Christian
04:40
created

AsmTranslationLoaderExtension::load()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 57
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 7.0261

Importance

Changes 13
Bugs 4 Features 1
Metric Value
c 13
b 4
f 1
dl 0
loc 57
ccs 34
cts 37
cp 0.9189
rs 7.6759
cc 7
eloc 31
nc 12
nop 2
crap 7.0261

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
 * @namespace Asm\TranslationLoaderBundle\DependencyInjection
4
 */
5
namespace Asm\TranslationLoaderBundle\DependencyInjection;
6
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
11
use Symfony\Component\DependencyInjection\Loader;
12
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
13
14
/**
15
 * This is the class that loads and manages your bundle configuration
16
 *
17
 * @package Asm\TranslationLoaderBundle\DependencyInjection
18
 * @author marc aschmann <[email protected]>
19
 * @uses Symfony\Component\DependencyInjection\ContainerBuilder
20
 * @uses Symfony\Component\Config\FileLocator
21
 * @uses Symfony\Component\HttpKernel\DependencyInjection\Extension
22
 * @uses Symfony\Component\DependencyInjection\Loader
23
 */
24
class AsmTranslationLoaderExtension extends Extension
25
{
26
    /**
27
     * {@inheritDoc}
28
     */
29 7
    public function load(array $configs, ContainerBuilder $container)
30
    {
31 7
        $configuration = new Configuration();
32 7
        $config = $this->processConfiguration($configuration, $configs);
33
34 7
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35 7
        $loader->load('services.yml');
36
37
        // set entity manager for translations
38 7
        $em = 'default';
39 7
        if (isset($config['database']['entity_manager'])
40 7
            && $config['database']['entity_manager'] != 'default'
41 7
        ) {
42
            $em = $config['database']['entity_manager'];
43
        }
44
45
        // association between file extensions and translation loader service ids
46 7
        $container->setParameter('asm_translation_loader.translation_loaders', $config['loaders']);
47 7
        $container->setParameter('asm_translation_loader.database.entity_manager', $em);
48
49 7
        $loader = new XmlFileLoader(
50 7
            $container,
51 7
            new FileLocator(__DIR__.'/../Resources/config')
52 7
        );
53
54
        // load the event dispatcher
55 7
        $loader->load('event_dispatcher.xml');
56
57
        // load the translation manager resource
58 7
        $container->setParameter('asm_translation_loader.resources', $config['resources']);
59 7
        $loader->load('translation_manager_resource.xml');
60
61
        // check if history feature is enabled
62 7
        if (isset($config['history']['enabled']) && true === $config['history']['enabled']) {
63 1
            $loader->load('translation_history_subscriber.xml');
64
65 1
            $definition = $container->getDefinition('asm_translation_loader.history.subscriber');
66
67 1
            if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
68 1
                $definition->replaceArgument(1, new Reference('security.token_storage'));
69 1
            } else {
70
                $definition->replaceArgument(1, new Reference('security.context'));
71
            }
72 1
        }
73
74 7
        $container->setParameter('asm_translation_loader.translation_manager.class', $config['translation_manager']);
75 7
        $container->setParameter('asm_translation_loader.translation_history_manager.class', $config['translation_history_manager']);
76 7
        $container->setParameter('asm_translation_loader.model.translation.class', $config['translation_class']);
77 7
        $container->setParameter('asm_translation_loader.model.translation_history.class', $config['translation_history_class']);
78
79 7
        if ('orm' == $config['driver']) {
80 7
            $loader->load('orm.xml');
81 7
        }
82
83
        // load the loader resolver service
84 7
        $loader->load('file_loader_resolver.xml');
85 7
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90 15
    public function getNamespace()
91
    {
92 15
        return 'https://github.com/maschmann/TranslationLoaderBundle/schema/dic';
93
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98 2
    public function getXsdValidationBasePath()
99
    {
100 2
        return __DIR__.'/../Resources/config/schema';
101
    }
102
}
103