Failed Conditions
Push — ng ( c00098...4b490a )
by Florent
06:57
created

UserinfoEndpointEncryptionSource   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 86
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 9 2
B getNodeDefinition() 0 37 3
A build() 0 4 1
A prepend() 0 10 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\Bundle\Component\OpenIdConnect;
15
16
use OAuth2Framework\Bundle\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 UserinfoEndpointEncryptionSource implements Component
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name(): string
28
    {
29
        return 'encryption';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
        if (!$configs['openid_connect']['userinfo_endpoint']['encryption']['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(NodeDefinition $node)
49
    {
50
        $node->children()
51
            ->arrayNode($this->name())
52
                ->canBeEnabled()
53
                ->addDefaultsIfNotSet()
54
                ->validate()
55
                    ->ifTrue(function ($config) {
56
                        return true === $config['enabled'] && empty($config['key_encryption_algorithms']);
57
                    })
58
                    ->thenInvalid('You must set at least one key encryption algorithm.')
59
                ->end()
60
                ->validate()
61
                    ->ifTrue(function ($config) {
62
                        return true === $config['enabled'] && empty($config['content_encryption_algorithms']);
63
                    })
64
                    ->thenInvalid('You must set at least one content encryption algorithm.')
65
                ->end()
66
                ->children()
67
                    ->arrayNode('key_encryption_algorithms')
68
                        ->info('Supported key encryption algorithms.')
69
                        ->useAttributeAsKey('name')
70
                        ->prototype('scalar')->end()
71
                        ->treatNullLike([])
72
                        ->treatFalseLike([])
73
                    ->end()
74
                    ->arrayNode('content_encryption_algorithms')
75
                        ->info('Supported content encryption algorithms.')
76
                        ->useAttributeAsKey('name')
77
                        ->prototype('scalar')->end()
78
                        ->treatNullLike([])
79
                        ->treatFalseLike([])
80
                    ->end()
81
                ->end()
82
            ->end()
83
        ->end();
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function build(ContainerBuilder $container)
90
    {
91
        //Nothing to do
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function prepend(ContainerBuilder $container, array $config): array
98
    {
99
        /*
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...
100
        $currentPath = $path.'['.$this->name().']';
101
        $accessor = PropertyAccess::createPropertyAccessor();
102
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
103
104
        ConfigurationHelper::addJWEBuilder($container, 'oauth2_server.userinfo', $sourceConfig['key_encryption_algorithms'], $sourceConfig['content_encryption_algorithms'], ['DEF'], false);*/
105
        return [];
106
    }
107
}
108