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

MetadataEndpointSource   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 93
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A name() 0 4 1
A load() 0 14 3
A getNodeDefinition() 0 17 2
A prepend() 0 12 2
A build() 0 7 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\Endpoint\Metadata;
15
16
use OAuth2Framework\Bundle\Component\Component;
17
use OAuth2Framework\Bundle\Component\ComponentWithCompilerPasses;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
22
23
class MetadataEndpointSource implements Component
24
{
25
    /**
26
     * @var Component[]
27
     */
28
    private $subComponents = [];
29
30
    /**
31
     * MetadataEndpointSource constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->subComponents = [
36
            new SignatureSource(),
37
            new CustomRouteSource(),
38
            new CustomValuesSource(),
39
        ];
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function name(): string
46
    {
47
        return 'metadata';
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function load(array $configs, ContainerBuilder $container)
54
    {
55
        if (!$configs['endpoint']['metadata']['enabled']) {
56
            return;
57
        }
58
        $container->setParameter('oauth2_server.endpoint.metadata.path', $configs['endpoint']['metadata']['path']);
59
60
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/metadata'));
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...
61
        //$loader->load('metadata.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...
62
63
        foreach ($this->subComponents as $subComponent) {
64
            $subComponent->load($configs, $container);
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getNodeDefinition(NodeDefinition $node)
72
    {
73
        $childNode = $node->children()
74
            ->arrayNode($this->name())
75
                ->addDefaultsIfNotSet()
76
                ->canBeEnabled();
77
78
        $childNode->children()
79
            ->scalarNode('path')
80
                ->defaultValue('/.well-known/openid-configuration')
81
            ->end()
82
        ->end();
83
84
        foreach ($this->subComponents as $subComponent) {
85
            $subComponent->getNodeDefinition($childNode);
86
        }
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function prepend(ContainerBuilder $container, array $config): array
93
    {
94
        $updatedConfig = [];
95
        foreach ($this->subComponents as $subComponent) {
96
            $updatedConfig = array_merge(
97
                $updatedConfig,
98
                $subComponent->prepend($container, $config)
99
            );
100
        }
101
102
        return $updatedConfig;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function build(ContainerBuilder $container)
109
    {
110
        //Nothing to do
111
        foreach ($this->subComponents as $component) {
112
            $component->build($container);
113
        };
114
    }
115
}
116