Athena::configureDashboardLogo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
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 Parthenon\Athena\Controller\AthenaControllerInterface;
25
use Parthenon\Athena\DashboardSectionInterface;
26
use Parthenon\Athena\Filters\FilterInterface;
27
use Parthenon\Athena\SectionInterface;
28
use Parthenon\Athena\ViewType\ViewTypeInterface;
29
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
30
use Symfony\Component\Config\FileLocator;
31
use Symfony\Component\DependencyInjection\ContainerBuilder;
32
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
33
34
final class Athena implements ModuleConfigurationInterface
35
{
36
    public function handleDefaultParameters(ContainerBuilder $container): void
37
    {
38
        $container->setParameter('parthenon_athena_host', null);
39
        $container->setParameter('parthenon_athena_login_logo', null);
40
        $container->setParameter('parthenon_athena_dashboard_logo', null);
41
    }
42
43
    public function handleConfiguration(array $config, ContainerBuilder $container): void
44
    {
45
        if (!isset($config['athena']) || !isset($config['athena']['enabled']) || false == $config['athena']['enabled']) {
46
            return;
47
        }
48
        $container->setParameter('parthenon_athena_enabled', true);
49
50
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
51
        $loader->load('services/athena.xml');
52
53
        $this->configureAutotagging($container);
54
55
        $config = $this->configureHost($config, $container);
56
        $config = $this->configureLoginLog($config, $container);
57
        $this->configureDashboardLogo($config, $container);
58
    }
59
60
    public function addConfig(NodeBuilder $nodeBuilder): void
61
    {
62
        $nodeBuilder
63
            ->arrayNode('athena')
64
                ->children()
65
                    ->booleanNode('enabled')->end()
66
                    ->scalarNode('host')->end()
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

66
                    ->/** @scrutinizer ignore-call */ scalarNode('host')->end()
Loading history...
67
                    ->scalarNode('login_logo')->end()
68
                    ->scalarNode('dashboard_logo')->end()
69
                ->end()
70
            ->end();
71
    }
72
73
    private function configureAutotagging(ContainerBuilder $container): void
74
    {
75
        $container->registerForAutoconfiguration(FilterInterface::class)->addTag('parthenon.athena.filter');
76
        $container->registerForAutoconfiguration(ViewTypeInterface::class)->addTag('parthenon.athena.view_type');
77
        $container->registerForAutoconfiguration(SectionInterface::class)->addTag('parthenon.athena.section');
78
        $container->registerForAutoconfiguration(DashboardSectionInterface::class)->addTag('parthenon.athena.dashboard_section');
79
        $container->registerForAutoconfiguration(AthenaControllerInterface::class)->addTag('parthenon.athena.controller');
80
    }
81
82
    private function configureHost(array $config, ContainerBuilder $container): array
83
    {
84
        if (isset($config['athena']['host'])) {
85
            $container->setParameter('parthenon_athena_host', $config['athena']['host']);
86
        }
87
88
        return $config;
89
    }
90
91
    private function configureLoginLog(array $config, ContainerBuilder $container): array
92
    {
93
        if (isset($config['athena']['login_logo'])) {
94
            $container->setParameter('parthenon_athena_login_logo', $config['athena']['login_logo']);
95
        }
96
97
        return $config;
98
    }
99
100
    private function configureDashboardLogo(array $config, ContainerBuilder $container): void
101
    {
102
        if (isset($config['athena']['dashboard_logo'])) {
103
            $container->setParameter('parthenon_athena_dashboard_logo', $config['athena']['dashboard_logo']);
104
        }
105
    }
106
}
107