Completed
Push — master ( c822b3...7bbc84 )
by Vyacheslav
11:42
created

NVBoosterPHPCRAssetsExtension::load()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 66
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 66
rs 8.6045
cc 6
eloc 44
nc 18
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
namespace NVBooster\PHPCRAssetsBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration
13
 *
14
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
15
 */
16
class NVBoosterPHPCRAssetsExtension extends Extension implements PrependExtensionInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function load(array $configs, ContainerBuilder $container)
22
    {
23
        $configuration = new Configuration();
24
        $config = $this->processConfiguration($configuration, $configs);
25
        
26
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27
        $loader->load('services.xml');        
28
        
29
        if (key_exists('codemirror', $config)) {
30
            $loader->load('form.xml');
31
        
32
             
33
            
34
            if (key_exists('paths', $config['codemirror'])) {
35
                $container
36
                    ->getDefinition('nvbooster_assets.twig_extension')
37
                    ->addArgument($config['codemirror']['paths']);
38
            }
39
            
40
            $container
41
                ->getDefinition('nvbooster_assets.formtype.asset')
42
                ->addArgument(array_merge(
43
                    array(
44
                        'theme' => 'eclipse', 
45
                        'mode' => 'xml',
46
                        'lineNumbers' => true
47
                        
48
                    ), $config['codemirror']['options']
49
                ));
50
        }
51
        
52
        $bundles = $container->getParameter('kernel.bundles');
53
        if (isset($bundles['SonataAdminBundle'])) {
54
            $loader->load('admin.xml');
55
            
56
            if (key_exists('codemirror', $config)) {
57
                $container
58
                    ->getDefinition('nvbooster_assets.asset_admin')
59
                    ->addMethodCall('enableCodeMirror');
60
                $container
61
                    ->getDefinition('nvbooster_assets.js_asset_admin')
62
                    ->addMethodCall('enableCodeMirror');
63
                $container
64
                    ->getDefinition('nvbooster_assets.css_asset_admin')
65
                    ->addMethodCall('enableCodeMirror');
66
            }
67
        }
68
        
69
        $container
70
            ->getDefinition('nvbooster_assets.routing.prefix_provider')
71
            ->replaceArgument(0, $config['routing']['base_uri']);
72
        
73
        if ($config['phpcr']['root_path']) {
74
            $container->setParameter('nvbooster_assets.phpcr.root', $config['phpcr']['root_path']);
75
        }
76
        
77
        $root = $container->getParameter('nvbooster_assets.phpcr.root');
78
        
79
        $container
80
            ->getDefinition('nvbooster_assets.phpcr.initializer')
81
            ->addArgument(array($root));
82
        
83
        $container
84
            ->getDefinition('nvbooster_assets.controller')
85
            ->addArgument($config['filters']);
86
    }
87
    
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function prepend(ContainerBuilder $container)
92
    {
93
        $config = array(
94
            'dynamic' => array(
95
                'controllers_by_class' => array(
96
                    'NVBooster\PHPCRAssetsBundle\Asset\JsAsset' => 'nvbooster_assets.controller:serveJs',
97
                    'NVBooster\PHPCRAssetsBundle\Asset\CssAsset' => 'nvbooster_assets.controller:serveCss',
98
                    'NVBooster\PHPCRAssetsBundle\Asset\BaseAsset' => 'nvbooster_assets.controller:serveAsset'
99
                )
100
            )
101
        );
102
    
103
        $container->prependExtensionConfig('cmf_routing', $config);
104
    }
105
    
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getAlias()
110
    {
111
        return 'nvbooster_assets';
112
    }
113
}
114