Failed Conditions
Push — ng ( 8fdb29...f5f23c )
by Florent
07:02
created

getNodeDefinition()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 20
nc 1
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\Component\OpenIdConnect;
15
16
use OAuth2Framework\Bundle\Component\Component;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
21
22
class UserinfoEndpointSignatureSource implements Component
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name(): string
28
    {
29
        return 'signature';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
        if (!$configs['openid_connect']['userinfo_endpoint']['signature']['enabled']) {
38
            return;
39
        }
40
41
        $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...
42
        //$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...
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode)
49
    {
50
        $node->children()
51
            ->arrayNode($this->name())
52
                ->canBeEnabled()
53
                ->validate()
54
                    ->ifTrue(function ($config) {
55
                        return true === $config['enabled'] && empty($config['signature_algorithms']);
56
                    })
57
                    ->thenInvalid('You must set at least one signature algorithm.')
58
                ->end()
59
                ->children()
60
                    ->arrayNode('signature_algorithms')
61
                        ->info('Signature algorithm used to sign the user information.')
62
                        ->useAttributeAsKey('name')
63
                        ->scalarPrototype()->end()
64
                        ->treatNullLike([])
65
                        ->treatFalseLike([])
66
                    ->end()
67
                ->end()
68
            ->end()
69
        ->end();
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function build(ContainerBuilder $container)
76
    {
77
        //Nothing to do
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function prepend(ContainerBuilder $container, array $config): array
84
    {
85
        /*Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
86
        $currentPath = $path.'['.$this->name().']';
87
        $accessor = PropertyAccess::createPropertyAccessor();
88
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
89
90
        ConfigurationHelper::addJWSBuilder($container, 'oauth2_server.userinfo', $sourceConfig['signature_algorithms'], false);*/
91
        return [];
92
    }
93
}
94