Passed
Push — main ( 68245a...b2eda1 )
by Axel
05:57
created

ZikulaUsersExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\UsersBundle\DependencyInjection;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
use Zikula\UsersBundle\Helper\MailHelper;
22
use Zikula\UsersBundle\Menu\ExtensionMenu;
23
24
class ZikulaUsersExtension extends Extension implements PrependExtensionInterface
25
{
26
    private ?bool $isNucleosSelfDeletionEnabled = null;
27
28
    public function prepend(ContainerBuilder $containerBuilder)
29
    {
30
        // get all bundles
31
        $bundles = $containerBuilder->getParameter('kernel.bundles');
32
        if (isset($bundles['NucleosUserBundle'])) {
33
            $config = $containerBuilder->getExtensionConfig('nucleos_user')[0];
34
            $this->isNucleosSelfDeletionEnabled = $config['deletion']['enabled'] ?? null;
35
        }
36
    }
37
38
    public function load(array $configs, ContainerBuilder $container)
39
    {
40
        $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config'));
41
        $loader->load('services.yaml');
42
43
        $configuration = new Configuration();
44
        $config = $this->processConfiguration($configuration, $configs);
45
46
        $container->getDefinition(MailHelper::class)
47
            ->setArgument('$registrationNotificationEmail', $config['registration']['admin_notification_mail']);
48
49
        $container->getDefinition(ExtensionMenu::class)
50
            ->setArgument('$registrationEnabled', $this->isNucleosSelfDeletionEnabled ?? $config['registration']['enabled'])
51
            ->setArgument('$allowSelfDeletion', $config['allow_self_deletion']);
52
    }
53
}
54