Failed Conditions
Push — ng ( 57a3a2...d2fe45 )
by Florent
03:39
created

TokenEndpointSource   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 74
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A name() 0 4 1
A load() 0 6 2
A getNodeDefinition() 0 19 2
A prepend() 0 12 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\DependencyInjection\Component\Endpoint\Token;
15
16
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
17
use OAuth2Framework\Component\TokenEndpoint\AuthenticationMethod\AuthenticationMethod;
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
final class TokenEndpointSource implements Component
24
{
25
    /**
26
     * @var Component[]
27
     */
28
    private $subComponents = [];
29
30
    /**
31
     * TokenEndpointSource constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->subComponents = [
36
            new TokenEndpointAuthMethodSource(),
37
        ];
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function name(): string
44
    {
45
        return 'token';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function load(array $configs, ContainerBuilder $container)
52
    {
53
        foreach ($this->subComponents as $subComponent) {
54
            $subComponent->load($configs, $container);
55
        }
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getNodeDefinition(NodeDefinition $node)
62
    {
63
        $childNode = $node->children()
64
            ->arrayNode($this->name())
65
                ->addDefaultsIfNotSet()
66
                ->canBeEnabled();
67
68
        $childNode
69
            ->children()
70
                ->scalarNode('path')
71
                    ->info('The token endpoint path')
72
                    ->defaultValue('/token/get')
73
                ->end()
74
            ->end();
75
76
        foreach ($this->subComponents as $subComponent) {
77
            $subComponent->getNodeDefinition($childNode);
78
        }
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function prepend(ContainerBuilder $container, array $config): array
85
    {
86
        $updatedConfig = [];
87
        foreach ($this->subComponents as $subComponent) {
88
            $updatedConfig = array_merge(
89
                $updatedConfig,
90
                $subComponent->prepend($container, $config)
91
            );
92
        }
93
94
        return $updatedConfig;
95
    }
96
}
97