Failed Conditions
Push — ng ( e90992...13fb6e )
by Florent
17:32
created

getNodeDefinition()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 27
nc 1
nop 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;
15
16
use Fluent\PhpConfigFileLoader;
17
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
22
final class ClientRegistrationInitialAccessTokenSource implements Component
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: load, prepend
Loading history...
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function continueLoading(string $path, ContainerBuilder $container, array $config)
28
    {
29
        foreach (['required', 'realm', 'authorization_header', 'query_string', 'request_body', 'min_length', 'max_length'] as $k) {
30
            $container->setParameter($path.'.'.$k, $config[$k]);
31
        }
32
        $container->setAlias($path.'.event_store', $config['event_store']);
33
34
        $loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint'));
35
        $loader->load('client_registration_initial_access_token.php');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function name(): string
42
    {
43
        return 'initial_access_token';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getNodeDefinition(NodeDefinition $node)
50
    {
51
52
        $node
53
            ->validate()
54
                ->ifTrue(function ($config) {
55
                    return true === $config['enabled'] && empty($config['realm']);
56
                })
57
                ->thenInvalid('The option "realm" must be set.')
58
            ->end()
59
            ->validate()
60
                ->ifTrue(function ($config) {
61
                    return true === $config['enabled'] && empty($config['event_store']);
62
                })
63
                ->thenInvalid('The option "event_store" must be set.')
64
            ->end()
65
            ->validate()
66
                ->ifTrue(function ($config) {
67
                    return true === $config['enabled'] && $config['max_length'] < $config['min_length'];
68
                })
69
                ->thenInvalid('The option "max_length" must be greater than "min_length".')
70
            ->end()
71
            ->children()
72
                ->booleanNode('required')->defaultFalse()->end()
73
                ->scalarNode('realm')->defaultNull()->end()
74
                ->booleanNode('authorization_header')->defaultTrue()->end()
75
                ->booleanNode('query_string')->defaultFalse()->end()
76
                ->booleanNode('request_body')->defaultFalse()->end()
77
                ->integerNode('min_length')->defaultValue(50)->min(0)->end()
78
                ->integerNode('max_length')->defaultValue(100)->min(1)->end()
79
                ->scalarNode('event_store')->defaultNull()->end()
80
            ->end();
81
    }
82
}
83