ResponseModeSource::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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\ServerBundle\Component\Endpoint\Authorization;
15
16
use OAuth2Framework\ServerBundle\Component\Component;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
21
22
class ResponseModeSource implements Component
23
{
24
    /**
25
     * @var Component[]
26
     */
27
    private $subComponents = [];
28
29
    public function __construct()
30
    {
31
        $this->subComponents = [
32
            new FormPostResponseModeSource(),
33
        ];
34
    }
35
36
    public function load(array $configs, ContainerBuilder $container): void
37
    {
38
        $config = $configs['endpoint']['authorization']['response_mode'];
39
        $container->setParameter('oauth2_server.endpoint.authorization.response_mode.allow_response_mode_parameter', $config['allow_response_mode_parameter']);
40
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/authorization'));
41
        $loader->load('response_mode.php');
42
43
        foreach ($this->subComponents as $subComponent) {
44
            $subComponent->load($configs, $container);
45
        }
46
    }
47
48
    public function name(): string
49
    {
50
        return 'response_mode';
51
    }
52
53
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode): void
54
    {
55
        $childNode = $node->children()
56
            ->arrayNode($this->name())
57
            ->addDefaultsIfNotSet()
58
            ->treatFalseLike([])
59
            ->treatNullLike([])
60
        ;
61
62
        $childNode->children()
63
            ->booleanNode('allow_response_mode_parameter')
64
            ->defaultFalse()
65
            ->end()
66
            ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            ->/** @scrutinizer ignore-call */ end()
Loading history...
67
        ;
68
69
        foreach ($this->subComponents as $subComponent) {
70
            $subComponent->getNodeDefinition($childNode, $node);
71
        }
72
    }
73
74
    public function prepend(ContainerBuilder $container, array $config): array
75
    {
76
        $updatedConfig = [];
77
        foreach ($this->subComponents as $subComponent) {
78
            $updatedConfig = array_merge(
79
                $updatedConfig,
80
                $subComponent->prepend($container, $config)
81
            );
82
        }
83
84
        return $updatedConfig;
85
    }
86
87
    public function build(ContainerBuilder $container): void
88
    {
89
        foreach ($this->subComponents as $component) {
90
            $component->build($container);
91
        }
92
    }
93
}
94