Passed
Branch master (c65ffc)
by Dāvis
03:08
created

SludioHelperExtension::load()   C

Complexity

Conditions 16
Paths 126

Size

Total Lines 55
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 37
nc 126
nop 2
dl 0
loc 55
rs 6.035
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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 Sludio\HelperBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension as BaseExtension;
9
10
/**
11
 * This is the class that loads and manages your bundle configuration.
12
 *
13
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
14
 */
15
class SludioHelperExtension extends BaseExtension
16
{
17
18
    public function getAlias()
19
    {
20
        return 'sludio_helper';
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load(array $configs, ContainerBuilder $container)
27
    {
28
        $configuration = new Configuration();
29
        $config = $this->processConfiguration($configuration, $configs);
30
31
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32
        $files = [
33
            'components.yml',
34
            'parameters.yml',
35
            'services.yml',
36
        ];
37
        foreach ($files as $file) {
38
            if (file_exists(__DIR__.'/../Resources/config/'.$file)) {
39
                $loader->load($file);
40
            }
41
        }
42
43
        foreach ($config['extensions'] as $key => $extension) {
44
            $enabled = $iterator = 0;
45
            $length = count($extension);
46
            foreach ($extension as $variable => $value) {
47
                $iterator++;
48
                if ($variable == 'enabled' && $value) {
49
                    $files = [
50
                        'components.yml',
51
                        'parameters.yml',
52
                        'services.yml',
53
                    ];
54
                    $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../'.ucfirst($key).'/Resources/config'));
55
                    foreach ($files as $file) {
56
                        if (file_exists(__DIR__.'/../'.ucfirst($key).'/Resources/config/'.$file)) {
57
                            $loader->load($file);
58
                        }
59
                    }
60
                    $enabled = 1;
61
                }
62
                if ($enabled === 1) {
63
                    $container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['extensions'][$key][$variable]);
64
                }
65
                if ($iterator === $length && $enabled === 1) {
66
                    $ext = new Extension($key);
67
                    if ($ext->getExtension()) {
68
                        $ext->configure($container);
69
                    }
70
                }
71
            }
72
        }
73
74
        foreach ($config['other'] as $key => $other) {
75
            if (is_array($other)) {
76
                foreach ($other as $variable => $value) {
77
                    $container->setParameter('sludio_helper.'.$key.'.'.$variable, $config['other'][$key][$variable]);
78
                }
79
            } else {
80
                $container->setParameter('sludio_helper.'.$key, $config['other'][$key]);
81
            }
82
        }
83
    }
84
}