Failed Conditions
Push — ng ( 962349...975869 )
by Florent
03:54
created

OpenIdConnectSource   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A name() 0 4 1
A load() 0 13 3
A getNodeDefinition() 0 11 2
A prepend() 0 12 2
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\Bundle\DependencyInjection\Component\OpenIdConnect;
15
16
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
17
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
21
22
class OpenIdConnectSource implements Component
23
{
24
    /**
25
     * @var Component[]
26
     */
27
    private $subComponents;
28
29
    public function __construct()
30
    {
31
        $this->subComponents = [
32
            new PairwiseSubjectSource(),
33
            new IdTokenSource(),
34
            new UserinfoEndpointSource(),
35
            new ResponseTypeSource(),
36
        ];
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function name(): string
43
    {
44
        return 'openid_connect';
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function load(array $configs, ContainerBuilder $container)
51
    {
52
        if (!$configs['openid_connect']['enabled']) {
53
            return;
54
        }
55
56
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/openid_connect'));
0 ignored issues
show
Unused Code introduced by
$loader is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
        //$loader->load('openid_connect.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
59
        foreach ($this->subComponents as $subComponent) {
60
            $subComponent->load($configs, $container);
61
        }
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getNodeDefinition(NodeDefinition $node)
68
    {
69
        $childNode = $node->children()
70
            ->arrayNode($this->name())
71
                ->canBeEnabled()
72
                ->addDefaultsIfNotSet();
73
74
        foreach ($this->subComponents as $subComponent) {
75
            $subComponent->getNodeDefinition($childNode);
76
        }
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function prepend(ContainerBuilder $container, array $config): array
83
    {
84
        $updatedConfig = [];
85
        foreach ($this->subComponents as $subComponent) {
86
            $updatedConfig = array_merge(
87
                $updatedConfig,
88
                $subComponent->prepend($container, $config)
89
            );
90
        }
91
92
        return $updatedConfig;
93
    }
94
}
95