Failed Conditions
Push — ng ( 020da0...94e2b6 )
by Florent
04:22
created

AuthorizationEndpointSource::getNodeDefinition()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 30
nc 2
nop 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\Authorization;
15
16
use OAuth2Framework\Bundle\Component\Component;
17
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
22
23
class AuthorizationEndpointSource implements Component
24
{
25
    /**
26
     * @var Component[]
27
     */
28
    private $subComponents = [];
29
30
    /**
31
     * AuthorizationEndpointSource constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->subComponents = [
36
        ];
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function name(): string
43
    {
44
        return 'authorization';
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function load(array $configs, ContainerBuilder $container)
51
    {
52
        if (!$configs['endpoint']['authorization']['enabled']) {
53
            return;
54
        }
55
56
        $container->registerForAutoconfiguration(ResponseType::class)->addTag('oauth2_server_response_type');
57
58
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/authorization'));
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...
59
        //$loader->load('authorization.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...
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode)
66
    {
67
        $childNode = $node->children()
68
            ->arrayNode($this->name())
69
                ->canBeEnabled()
70
                ->addDefaultsIfNotSet();
71
72
        $childNode->children()
73
            ->scalarNode('path')
74
                ->info('The path to the authorization endpoint.')
75
                ->defaultValue('/authorize')
76
            ->end()
77
            ->scalarNode('login_route_name')
78
                ->info('The name of the login route. Will be converted into URL and used to redirect the user if not logged in. If you use "FOSUserBundle", the route name should be "fos_user_security_login".')
79
            ->end()
80
            ->arrayNode('login_route_parameters')
81
                ->info('Parameters associated to the login route (optional).')
82
                ->useAttributeAsKey('name')
83
                ->scalarPrototype()->end()
84
                ->treatNullLike([])
85
            ->end()
86
            ->scalarNode('template')
87
                ->info('The consent page template.')
88
                ->defaultValue('@OAuth2FrameworkBundle/authorization/authorization.html.twig')
89
            ->end()
90
            ->scalarNode('enforce_state')
91
                ->info('If true the "state" parameter is mandatory (recommended).')
92
                ->defaultFalse()
93
            ->end()
94
        ->end();
95
96
        foreach ($this->subComponents as $subComponent) {
97
            $subComponent->getNodeDefinition($childNode, $node);
98
        }
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function prepend(ContainerBuilder $container, array $config): array
105
    {
106
        $updatedConfig = [];
107
        foreach ($this->subComponents as $subComponent) {
108
            $updatedConfig = array_merge(
109
                $updatedConfig,
110
                $subComponent->prepend($container, $config)
111
            );
112
        }
113
114
        return $updatedConfig;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function build(ContainerBuilder $container)
121
    {
122
        foreach ($this->subComponents as $component) {
123
            $component->build($container);
124
        }
125
    }
126
}
127