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

UserinfoEndpointSource::prepend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 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 OAuth2Framework\Bundle\DependencyInjection\Component\Grant\AuthorizationCode\AuthorizationCodeSource;
18
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\ClientCredentials\ClientCredentialsSource;
19
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\Implicit\ImplicitSource;
20
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\JwtBearer\JwtBearerSource;
21
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\None\NoneSource;
22
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\RefreshToken\RefreshTokenSource;
23
use OAuth2Framework\Bundle\DependencyInjection\Component\Grant\ResourceOwnerPasswordCredential\ResourceOwnerPasswordCredentialSource;
24
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType;
25
use OAuth2Framework\Component\TokenEndpoint\GrantType;
26
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
27
use Symfony\Component\Config\FileLocator;
28
use Symfony\Component\DependencyInjection\ContainerBuilder;
29
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
30
31
class UserinfoEndpointSource implements Component
32
{
33
    /**
34
     * @var Component[]
35
     */
36
    private $subComponents;
37
38
    public function __construct()
39
    {
40
        $this->subComponents = [
41
            new UserinfoEndpointSignatureSource(),
42
            new UserinfoEndpointEncryptionSource(),
43
        ];
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function name(): string
50
    {
51
        return 'userinfo_endpoint';
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function load(array $configs, ContainerBuilder $container)
58
    {
59
        if (!$configs['openid_connect']['userinfo_endpoint']['enabled']) {
60
            return;
61
        }
62
63
        $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...
64
        //$loader->load('userinfo_endpoint.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...
65
66
        foreach ($this->subComponents as $subComponent) {
67
            $subComponent->load($configs, $container);
68
        }
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getNodeDefinition(NodeDefinition $node)
75
    {
76
        $childNode = $node->children()
77
            ->arrayNode($this->name())
78
                ->canBeEnabled()
79
                ->addDefaultsIfNotSet();
80
81
        $childNode->children()
82
            ->scalarNode('path')
83
                ->defaultValue('/userinfo')
84
            ->end()
85
        ->end();
86
87
        foreach ($this->subComponents as $subComponent) {
88
            $subComponent->getNodeDefinition($childNode);
89
        }
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function prepend(ContainerBuilder $container, array $config): array
96
    {
97
        $updatedConfig = [];
98
        foreach ($this->subComponents as $subComponent) {
99
            $updatedConfig = array_merge(
100
                $updatedConfig,
101
                $subComponent->prepend($container, $config)
102
            );
103
        }
104
105
        return $updatedConfig;
106
    }
107
}
108