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

SignatureSource   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 4 1
B getNodeDefinition() 0 28 3
A prepend() 0 13 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\DependencyInjection\Component\Endpoint\Metadata;
15
16
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
17
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
class SignatureSource implements Component
21
{
22
    /**
23
     * @return string
24
     */
25
    public function name(): string
26
    {
27
        return 'signature';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function load(array $configs, ContainerBuilder $container)
34
    {
35
        $container->setParameter('oauth2_server.endpoint.metadata.custom_routes', $configs['endpoint']['metadata']['custom_routes']);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getNodeDefinition(NodeDefinition $node)
42
    {
43
        $node->children()
44
            ->arrayNode('signature')
45
                ->canBeEnabled()
46
                ->validate()
47
                    ->ifTrue(function ($config) {
48
                        return true === $config['enabled'] && empty($config['algorithm']);
49
                    })
50
                    ->thenInvalid('The signature algorithm must be set.')
51
                ->end()
52
                ->validate()
53
                    ->ifTrue(function ($config) {
54
                        return true === $config['enabled'] && empty($config['key']);
55
                    })
56
                    ->thenInvalid('The signature key must be set.')
57
                ->end()
58
                ->children()
59
                    ->scalarNode('algorithm')
60
                        ->info('Signature algorithm used to sign the metadata.')
61
                    ->end()
62
                    ->scalarNode('key')
63
                        ->info('Signature key.')
64
                    ->end()
65
                ->end()
66
            ->end()
67
        ->end();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function prepend(ContainerBuilder $container, array $config): array
74
    {
75
        /*parent::prepend($bundleConfig, $path, $container);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
76
        $currentPath = $path.'['.$this->name().']';
77
        $accessor = PropertyAccess::createPropertyAccessor();
78
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
79
80
        ConfigurationHelper::addJWSBuilder($container, 'metadata_signature', [$sourceConfig['algorithm']], false);
81
82
        Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.');*/
83
        //ConfigurationHelper::addKeyset($container, 'signed_metadata_endpoint.key_set.signature', 'jwkset', ['value' => $bundleConfig['key_set']['signature']]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
84
        return [];
85
    }
86
}
87