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

IdTokenSource::getNodeDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 9.0335
c 0
b 0
f 0
cc 1
eloc 69
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 IdTokenSource implements Component
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name(): string
28
    {
29
        return 'id_token';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getNodeDefinition(NodeDefinition $node)
43
    {
44
        $node->children()
45
            ->arrayNode($this->name())
46
                ->addDefaultsIfNotSet()
47
                ->validate()
48
                    ->ifTrue(function ($config) {
49
                        return empty($config['default_signature_algorithm']);
50
                    })
51
                    ->thenInvalid('The option "default_signature_algorithm" must be set.')
52
                ->end()
53
                ->validate()
54
                    ->ifTrue(function ($config) {
55
                        return empty($config['signature_algorithms']);
56
                    })
57
                    ->thenInvalid('The option "signature_algorithm" must contain at least one signature algorithm.')
58
                ->end()
59
                ->validate()
60
                    ->ifTrue(function ($config) {
61
                        return !in_array($config['default_signature_algorithm'], $config['signature_algorithms']);
62
                    })
63
                    ->thenInvalid('The default signature algorithm must be in the supported signature algorithms.')
64
                ->end()
65
                ->children()
66
                    ->scalarNode('default_signature_algorithm')
67
                    ->info('Signature algorithm used if the client has not defined a preferred one. Recommended value is "RS256".')
68
                ->end()
69
                ->arrayNode('signature_algorithms')
70
                    ->info('Signature algorithm used to sign the ID Tokens.')
71
                    ->useAttributeAsKey('name')
72
                    ->prototype('scalar')->end()
73
                    ->treatNullLike([])
74
                    ->treatFalseLike([])
75
                ->end()
76
                ->arrayNode('claim_checkers')
77
                    ->info('Checkers will verify the JWT claims.')
78
                    ->useAttributeAsKey('name')
79
                    ->prototype('scalar')->end()
80
                    ->treatNullLike(['exp', 'iat', 'nbf'])
81
                ->end()
82
                ->arrayNode('header_checkers')
83
                    ->info('Checkers will verify the JWT headers.')
84
                    ->useAttributeAsKey('name')
85
                    ->prototype('scalar')->end()
86
                    ->treatNullLike([])
87
                    ->treatFalseLike([])
88
                ->end()
89
                ->integerNode('lifetime')
90
                    ->info('Lifetime of the ID Tokens (in seconds). If an access token is issued with the ID Token, the lifetime of the access token is used instead of this value.')
91
                    ->defaultValue(3600)
92
                    ->min(1)
93
                ->end()
94
                ->arrayNode('encryption')
95
                    ->canBeEnabled()
96
                    ->children()
97
                        ->arrayNode('key_encryption_algorithms')
98
                            ->info('Supported key encryption algorithms.')
99
                            ->useAttributeAsKey('name')
100
                            ->prototype('scalar')->end()
101
                            ->treatNullLike([])
102
                            ->treatFalseLike([])
103
                        ->end()
104
                        ->arrayNode('content_encryption_algorithms')
105
                            ->info('Supported content encryption algorithms.')
106
                            ->useAttributeAsKey('name')
107
                            ->prototype('scalar')->end()
108
                            ->treatNullLike([])
109
                            ->treatFalseLike([])
110
                        ->end()
111
                    ->end()
112
                ->end()
113
            ->end()
114
        ->end();
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function prepend(ContainerBuilder $container, array $config): array
121
    {
122
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
123
        $currentPath = $path.'['.$this->name().']';
124
        $accessor = PropertyAccess::createPropertyAccessor();
125
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
126
        ConfigurationHelper::addJWSBuilder($container, $this->name(), $sourceConfig['signature_algorithms'], false);
127
        ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['signature_algorithms'], [], ['jws_compact'], false);
128
129
        Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.');
130
        //ConfigurationHelper::addKeyset($container, 'id_token.key_set.signature', 'jwkset', ['value' => $bundleConfig['key_set']['signature']]);
131
         */
132
        return [];
133
    }
134
}
135