Failed Conditions
Push — ng ( fe3ccc...89ffb0 )
by Florent
09:19
created

IssuerDiscoveryCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 47 3
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\IssuerDiscovery;
15
16
use OAuth2Framework\Bundle\Routing\RouteLoader;
17
use OAuth2Framework\Bundle\Service\IssuerDiscoveryFactory;
18
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\IssuerDiscoveryEndpoint;
19
use OAuth2Framework\Component\Middleware\OAuth2ResponseMiddleware;
20
use OAuth2Framework\Component\Middleware\Pipe;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Definition;
24
use Symfony\Component\DependencyInjection\Reference;
25
26
class IssuerDiscoveryCompilerPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container)
32
    {
33
        if (!$container->hasDefinition(IssuerDiscoveryFactory::class)) {
34
            return;
35
        }
36
37
        $issuerDiscoveries = $container->getParameter('oauth2_server.endpoint.issuer_discovery');
38
39
        foreach ($issuerDiscoveries as $id => $issuerDiscovery) {
40
            $issuerDiscoveryId = sprintf('oauth2_server_issuer_discovery_%s', $id);
41
            $issuerDiscoveryDefinition = (new Definition())
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $issuerDiscoveryDefinition exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
42
                ->setFactory([new Reference(IssuerDiscoveryFactory::class), 'create'])
43
                ->setClass(IssuerDiscoveryEndpoint::class)
44
                ->setArguments([
45
                    new Reference($issuerDiscovery['resource_repository']),
46
                    $issuerDiscovery['server'],
47
                ]);
48
            $container->setDefinition($issuerDiscoveryId, $issuerDiscoveryDefinition);
49
            $container->setDefinition($issuerDiscoveryId, $issuerDiscoveryDefinition);
50
51
            $issuerDiscoveryPipeId = sprintf('oauth2_server_issuer_discovery_pipe_%s', $id);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $issuerDiscoveryPipeId exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
52
            $issuerDiscoveryPipeDefinition = (new Definition())
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $issuerDiscoveryPipeDefinition exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
53
                ->setClass(Pipe::class)
54
                ->setArguments([[
55
                    new Reference(OAuth2ResponseMiddleware::class),
56
                    new Reference($issuerDiscoveryId),
57
                ]])
58
                ->setPublic(true) //FIXME
59
                ->addTag('controller.service_arguments');
60
            $container->setDefinition($issuerDiscoveryPipeId, $issuerDiscoveryPipeDefinition);
61
62
            $route_loader = $container->getDefinition(RouteLoader::class);
63
            $route_loader->addMethodCall('addRoute', [
64
                $id,
65
                $issuerDiscoveryPipeId,
66
                'dispatch',
67
                $issuerDiscovery['path'],
68
                [], // defaults
69
                [], // requirements
70
                [], // options
71
                $issuerDiscovery['host'], // host
72
                ['https'], // schemes
73
                ['GET'], // methods
74
                '', // condition
75
            ]);
76
        }
77
    }
78
}
79