Completed
Push — master ( f41515...ea4213 )
by Benjamin
02:08
created

AlpixelCMSBundle   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getContainerExtension() 0 31 6
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle;
4
5
use Symfony\Component\DependencyInjection\Container;
6
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
7
use Symfony\Component\HttpKernel\Bundle\Bundle;
8
9
class AlpixelCMSBundle extends Bundle
10
{
11
    /**
12
     * Returns the bundle's container extension.
13
     *
14
     * @return ExtensionInterface|null The container extension
15
     *
16
     * @throws \LogicException
17
     */
18
    public function getContainerExtension()
19
    {
20
        if (null === $this->extension) {
21
            $extension = $this->createContainerExtension();
22
23
            if (null !== $extension) {
24
                if (!$extension instanceof ExtensionInterface) {
25
                    throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_class($extension)));
26
                }
27
28
                // check naming convention
29
                $basename = preg_replace('/Bundle$/', '', $this->getName());
30
                $expectedAlias = Container::underscore($basename);
31
32
                if ($expectedAlias != $extension->getAlias()) {
33
                    throw new \LogicException(sprintf(
34
                        'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
35
                        $expectedAlias, $extension->getAlias()
36
                    ));
37
                }
38
39
                $this->extension = $extension;
40
            } else {
41
                $this->extension = false;
42
            }
43
        }
44
45
        if ($this->extension) {
46
            return $this->extension;
47
        }
48
    }
49
50
}
51