Failed Conditions
Push — master ( 349866...67c1d1 )
by Florent
10:56 queued 06:08
created

OAuth2FrameworkSecurityBundle   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainerExtension() 0 4 1
A build() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\SecurityBundle;
15
16
use OAuth2Framework\SecurityBundle\DependencyInjection\Compiler\AccessTokenHandlerCompilerPass;
17
use OAuth2Framework\SecurityBundle\DependencyInjection\Compiler\SecurityAnnotationCheckerCompilerPass;
18
use OAuth2Framework\SecurityBundle\DependencyInjection\Compiler\TokenTypeCompilerPass;
19
use OAuth2Framework\SecurityBundle\DependencyInjection\OAuth2FrameworkSecurityExtension;
20
use OAuth2Framework\SecurityBundle\Security\Factory\OAuth2SecurityFactory;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\HttpKernel\Bundle\Bundle;
23
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
24
25
final class OAuth2FrameworkSecurityBundle extends Bundle
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getContainerExtension()
31
    {
32
        return new OAuth2FrameworkSecurityExtension('oauth2_security');
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function build(ContainerBuilder $container)
39
    {
40
        if (!$container->hasExtension('security')) {
41
            throw new \RuntimeException('The security extension is not available');
42
        }
43
        $extension = $container->getExtension('security');
44
        if (!$extension instanceof SecurityExtension) {
0 ignored issues
show
Bug introduced by
The class Symfony\Bundle\SecurityB...ction\SecurityExtension does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
            throw new \RuntimeException('Unsupported security extension');
46
        }
47
        $extension->addSecurityListenerFactory(new OAuth2SecurityFactory());
48
49
        $container->addCompilerPass(new SecurityAnnotationCheckerCompilerPass());
50
        $container->addCompilerPass(new AccessTokenHandlerCompilerPass());
51
        $container->addCompilerPass(new TokenTypeCompilerPass());
52
    }
53
}
54