Failed Conditions
Pull Request — master (#47)
by Florent
06:42
created

JKUSource   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 10 2
A getNodeDefinition() 0 20 1
A prepend() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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 Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\Config\FileLocator;
21
22
/**
23
 * Class JKUSource.
24
 */
25
final class JKUSource implements Source
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function name(): string
31
    {
32
        return 'jku_factory';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function load(array $configs, ContainerBuilder $container)
39
    {
40
        if (true === $configs[$this->name()]['enabled']) {
41
            $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
42
            $loader->load('jku_source.yml');
43
            $loader->load('jku_commands.yml');
44
            $container->setAlias('jose.http_client', $configs[$this->name()]['client']);
45
            $container->setAlias('jose.request_factory', $configs[$this->name()]['request_factory']);
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getNodeDefinition(ArrayNodeDefinition $node)
53
    {
54
        $node
55
            ->children()
56
                ->arrayNode('jku_factory')
57
                    ->canBeEnabled()
58
                    ->children()
59
                        ->scalarNode('client')
60
                            ->info('HTTP Client used to retrieve key sets.')
61
                            ->isRequired()
62
                            ->defaultNull()
63
                        ->end()
64
                        ->scalarNode('request_factory')
65
                            ->info('The request factory service.')
66
                            ->isRequired()
67
                        ->end()
68
                    ->end()
69
                ->end()
70
            ->end();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function prepend(ContainerBuilder $container, array $config): array
77
    {
78
        return [];
79
    }
80
}
81