Failed Conditions
Push — master ( b8d841...bc596e )
by Florent
28:20
created

OAuth2FrameworkWebFingerExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 34
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAlias() 0 4 1
A load() 0 14 1
A getConfiguration() 0 4 1
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\WebFingerBundle\DependencyInjection;
15
16
use OAuth2Framework\Component\WebFingerEndpoint\IdentifierResolver\IdentifierResolver;
17
use Symfony\Component\Config\Definition\Processor;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
21
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22
23
class OAuth2FrameworkWebFingerExtension extends Extension
24
{
25
    private $alias;
26
27
    public function __construct(string $alias)
28
    {
29
        $this->alias = $alias;
30
    }
31
32
    public function getAlias()
33
    {
34
        return $this->alias;
35
    }
36
37
    public function load(array $configs, ContainerBuilder $container)
38
    {
39
        $processor = new Processor();
40
        $config = $processor->processConfiguration($this->getConfiguration($configs, $container), $configs);
0 ignored issues
show
Bug introduced by
It seems like $this->getConfiguration($configs, $container) can be null; however, processConfiguration() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
41
42
        $container->registerForAutoconfiguration(IdentifierResolver::class)->addTag('webfinger_identifier_resolver');
43
        $container->setAlias('webfinger.response_factory', $config['response_factory']);
44
        $container->setAlias('webfinger.resource_repository', $config['resource_repository']);
45
        $container->setParameter('webfinger.host', $config['host']);
46
        $container->setParameter('webfinger.path', $config['path']);
47
48
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
49
        $loader->load('services.php');
50
    }
51
52
    public function getConfiguration(array $config, ContainerBuilder $container)
53
    {
54
        return new Configuration($this->alias);
55
    }
56
}
57