EoHoneypotExtension::load()   A
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 7
nop 2
dl 0
loc 30
rs 9.1288
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the EoHoneypotBundle package.
5
 *
6
 * (c) Eymen Gunay <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Eo\HoneypotBundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17
use Symfony\Component\DependencyInjection\Loader;
18
use Symfony\Component\DependencyInjection\Reference;
19
use Symfony\Component\DependencyInjection\Definition;
20
21
/**
22
 * This is the class that loads and manages your bundle configuration
23
 *
24
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
25
 */
26
class EoHoneypotExtension extends Extension
27
{
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function load(array $configs, ContainerBuilder $container)
32
    {
33
        $configuration = new Configuration();
34
        $config = $this->processConfiguration($configuration, $configs);
35
36
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
37
        $loader->load('services.xml');
38
39
        // Set db
40
        if ($config['storage']['database']['enabled']) {
41
            switch ($config['storage']['database']['driver']) {
42
                case 'orm':
43
                    $db = new Reference('doctrine.orm.entity_manager');
44
                    break;
45
                case 'mongodb':
46
                    $db = new Reference('doctrine.odm.mongodb.document_manager');
47
                    break;
48
                default:
49
                    throw new \LogicException("Invalid db driver given");
50
                    break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
51
            }
52
            $container->getDefinition('eo_honeypot.manager')->addMethodCall('setObjectManager', array($db));
53
        }
54
        $container->setParameter('eo_honeypot.options', $config);
55
56
        // Remove RedirectListener if redirect is disabled
57
        if (!$config['redirect']['enabled']) {
58
            $container->removeDefinition('eo_honeypot.redirect_listener');
59
        }
60
    }
61
}
62