Completed
Push — master ( aa6f89...863f7f )
by John
08:07
created

KleijnWebSwaggerBundle::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle;
10
11
use KleijnWeb\SwaggerBundle\DependencyInjection\KleijnWebSwaggerExtension;
12
use KleijnWeb\SwaggerBundle\DependencyInjection\SwaggerRequestAuthorizationFactory;
13
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
16
use Symfony\Component\HttpKernel\Bundle\Bundle;
17
18
/**
19
 * @author John Kleijn <[email protected]>
20
 */
21
class KleijnWebSwaggerBundle extends Bundle
22
{
23
    /**
24
     * @return string The Bundle namespace
25
     */
26
    public function getNamespace()
27
    {
28
        return __NAMESPACE__;
29
    }
30
31
    public function build(ContainerBuilder $container)
32
    {
33
        parent::build($container);
34
35
        if ($container->hasExtension('security')) {
36
            /** @var SecurityExtension $extension */
37
            $extension = $container->getExtension('security');
38
            $extension->addSecurityListenerFactory(new SwaggerRequestAuthorizationFactory());
39
        }
40
    }
41
42
    /**
43
     * @return ExtensionInterface
44
     */
45
    public function getContainerExtension()
46
    {
47
        if (null === $this->extension) {
48
            $this->extension = new KleijnWebSwaggerExtension();
49
        }
50
51
        return $this->extension;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $this->extension; of type Symfony\Component\Depend...xtensionInterface|false adds false to the return on line 51 which is incompatible with the return type declared by the interface Symfony\Component\HttpKe...::getContainerExtension of type Symfony\Component\Depend...ExtensionInterface|null. It seems like you forgot to handle an error condition.
Loading history...
52
    }
53
}
54