Failed Conditions
Push — ng ( c7c973...483bed )
by Florent
04:16
created

PKCEMethodCompilerPass::process()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.439
c 0
b 0
f 0
cc 6
eloc 16
nc 8
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\Component\Grant\AuthorizationCode;
15
16
use OAuth2Framework\Bundle\Service\MetadataBuilder;
17
use OAuth2Framework\Component\AuthorizationCodeGrant\PKCEMethod\PKCEMethodManager;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
class PKCEMethodCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        if (!$container->hasDefinition(PKCEMethodManager::class)) {
30
            return;
31
        }
32
33
        $definition = $container->getDefinition(PKCEMethodManager::class);
34
35
        $taggedServices = $container->findTaggedServiceIds('oauth2_server_pkce_method');
36
        $loaded = [];
37
        foreach ($taggedServices as $id => $tags) {
38
            foreach ($tags as $attributes) {
39
                if (!array_key_exists('alias', $attributes)) {
40
                    throw new \InvalidArgumentException(sprintf('The PKCE method  "%s" does not have any "alias" attribute.', $id));
41
                }
42
                $loaded[] = $attributes['alias'];
43
                $definition->addMethodCall('add', [new Reference($id)]);
44
            }
45
        }
46
47
        if (!$container->hasDefinition(MetadataBuilder::class)) {
48
            return;
49
        }
50
51
        $definition = $container->getDefinition(MetadataBuilder::class);
52
        $definition->addMethodCall('setCodeChallengeMethodsSupported', [new Reference(PKCEMethodManager::class)]);
53
    }
54
}
55