Cloud::addConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\DependencyInjection\Modules;
23
24
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
25
use Symfony\Component\Config\FileLocator;
26
use Symfony\Component\DependencyInjection\ContainerBuilder;
27
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
28
29
final class Cloud implements ModuleConfigurationInterface
30
{
31
    public function addConfig(NodeBuilder $nodeBuilder): void
32
    {
33
        $nodeBuilder->arrayNode('cloud')
34
            ->children()
35
                ->booleanNode('enabled')->defaultFalse()->end()
36
                ->arrayNode('digitalocean')
0 ignored issues
show
Bug introduced by
The method arrayNode() 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

36
                ->/** @scrutinizer ignore-call */ arrayNode('digitalocean')
Loading history...
37
                    ->children()
38
                        ->scalarNode('api_key')->end()
39
                    ?->end()
40
                ->end()
41
        ->end();
42
    }
43
44
    public function handleDefaultParameters(ContainerBuilder $container): void
45
    {
46
        $container->setParameter('parthenon_cloud_digitalocean_apikey', '');
47
    }
48
49
    public function handleConfiguration(array $config, ContainerBuilder $container): void
50
    {
51
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
52
53
        if (!isset($config['cloud']) || !isset($config['cloud']['enabled']) || false === $config['cloud']['enabled']) {
54
            return;
55
        }
56
        $loader->load('services/cloud.xml');
57
        $this->handleDigitalOcean($config, $container);
58
    }
59
60
    private function handleDigitalOcean(array $config, ContainerBuilder $containerBuilder): void
61
    {
62
        if (!isset($config['cloud']['digitalocean'])) {
63
            return;
64
        }
65
66
        $digitalOceanConfig = $config['cloud']['digitalocean'];
67
68
        $containerBuilder->setParameter('parthenon_cloud_digitalocean_apikey', $digitalOceanConfig['api_key'] ?? '');
69
    }
70
}
71