Failed Conditions
Push — ng ( 2223e4...efd567 )
by Florent
19:20 queued 15:36
created

AuthorizationCodeSource::getNodeDefinition()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 19
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\Grant;
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 AuthorizationCodeSource 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 (['min_length', 'max_length', 'lifetime', 'enforce_pkce'] 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/grant'));
35
        $loader->load('authorization_code.php');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function name(): string
42
    {
43
        return 'authorization_code';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getNodeDefinition(NodeDefinition $node)
50
    {
51
        $node
52
            ->validate()
53
                ->ifTrue(function ($config) {
54
                    return true === $config['enabled'] && empty($config['event_store']);
55
                })
56
                ->thenInvalid('The option "event_store" must be set.')
57
            ->end()
58
            ->validate()
59
                ->ifTrue(function ($config) {
60
                    return true === $config['enabled'] && $config['max_length'] < $config['min_length'];
61
                })
62
                ->thenInvalid('The option "max_length" must be greater than "min_length".')
63
            ->end()
64
            ->children()
65
                ->integerNode('min_length')->defaultValue(50)->min(0)->end()
66
                ->integerNode('max_length')->defaultValue(100)->min(1)->end()
67
                ->integerNode('lifetime')->defaultValue(30)->min(1)->end()
68
                ->scalarNode('event_store')->defaultNull()->end()
69
                ->booleanNode('enforce_pkce')->defaultFalse()->end()
70
            ->end();
71
    }
72
}
73