TokenRevocationEndpointSource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
c 0
b 0
f 0
dl 0
loc 67
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 17 3
A name() 0 3 1
A getNodeDefinition() 0 26 2
A build() 0 7 2
A prepend() 0 3 1
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\TokenRevocation;
15
16
use OAuth2Framework\Component\TokenRevocationEndpoint\TokenRevocationEndpoint;
17
use OAuth2Framework\Component\TokenRevocationEndpoint\TokenTypeHint;
18
use OAuth2Framework\ServerBundle\Component\Component;
19
use OAuth2Framework\ServerBundle\Component\Endpoint\TokenRevocation\Compiler\TokenRevocationRouteCompilerPass;
20
use OAuth2Framework\ServerBundle\Component\Endpoint\TokenRevocation\Compiler\TokenTypeHintCompilerPass;
21
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
22
use Symfony\Component\Config\FileLocator;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
25
26
class TokenRevocationEndpointSource implements Component
27
{
28
    public function name(): string
29
    {
30
        return 'token_revocation';
31
    }
32
33
    public function load(array $configs, ContainerBuilder $container): void
34
    {
35
        if (!class_exists(TokenRevocationEndpoint::class)) {
36
            return;
37
        }
38
        $config = $configs['endpoint']['token_revocation'];
39
        $container->setParameter('oauth2_server.endpoint.token_revocation.enabled', $config['enabled']);
40
        if (!$config['enabled']) {
41
            return;
42
        }
43
        $container->registerForAutoconfiguration(TokenTypeHint::class)->addTag('oauth2_server_revocation_type_hint');
44
        $container->setParameter('oauth2_server.endpoint.token_revocation.path', $config['path']);
45
        $container->setParameter('oauth2_server.endpoint.token_revocation.host', $config['host']);
46
        $container->setParameter('oauth2_server.endpoint.token_revocation.allow_callback', $config['allow_callback']);
47
48
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/token_revocation'));
49
        $loader->load('revocation.php');
50
    }
51
52
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode): void
53
    {
54
        if (!class_exists(TokenRevocationEndpoint::class)) {
55
            return;
56
        }
57
        $node->children()
58
            ->arrayNode($this->name())
59
            ->canBeEnabled()
60
            ->children()
61
            ->scalarNode('path')
62
            ->info('The token revocation endpoint path')
63
            ->defaultValue('/token/revocation')
64
            ->end()
65
            ->scalarNode('host')
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

65
            ->/** @scrutinizer ignore-call */ scalarNode('host')
Loading history...
66
            ->info('If set, the route will be limited to that host')
67
            ->defaultValue('')
68
            ->treatNullLike('')
69
            ->treatFalseLike('')
70
            ->end()
71
            ->booleanNode('allow_callback')
72
            ->info('If true, GET request with "callback" parameter are allowed.')
73
            ->defaultFalse()
74
            ->end()
75
            ->end()
76
            ->end()
77
            ->end()
78
        ;
79
    }
80
81
    public function build(ContainerBuilder $container): void
82
    {
83
        if (!class_exists(TokenRevocationEndpoint::class)) {
84
            return;
85
        }
86
        $container->addCompilerPass(new TokenTypeHintCompilerPass());
87
        $container->addCompilerPass(new TokenRevocationRouteCompilerPass());
88
    }
89
90
    public function prepend(ContainerBuilder $container, array $config): array
91
    {
92
        return [];
93
    }
94
}
95