Passed
Pull Request — master (#262)
by Arnaud
03:22
created

LAGAdminExtension::load()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5.0406

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 16
c 3
b 0
f 0
dl 0
loc 25
ccs 15
cts 17
cp 0.8824
rs 9.4222
cc 5
nc 12
nop 2
crap 5.0406
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\DependencyInjection;
6
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
10
use Symfony\Component\DependencyInjection\Loader;
11
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
12
13
class LAGAdminExtension extends Extension implements PrependExtensionInterface
14
{
15 3
    public function load(array $configs, ContainerBuilder $container): void
16
    {
17 3
        $configuration = new Configuration();
18 3
        $config = $this->processConfiguration($configuration, $configs);
19
20 3
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
21 3
        $loader->load('services.yaml');
22
23 3
        if ($container->getParameter('kernel.environment') === 'dev') {
24 2
            $loader->load('services_dev.yaml');
25
        }
26
27 3
        if ($container->getParameter('kernel.environment') === 'prod') {
28
            if (!\array_key_exists('application', $config)) {
29
                $config['resources_path'] = '%kernel.project_dir%/config/admin/resources';
30
            }
31
        }
32 3
        if (!\array_key_exists('menus', $config)) {
33 3
            $config['menus'] = [];
34
        }
35 3
        $container->setParameter('lag_admin.application.configuration', $config);
36 3
        $container->setParameter('lag_admin.menu.menus', $config['menus']);
37 3
        $container->setParameter('lag_admin.resources.path', $config['resources_path']);
38 3
        $container->setParameter('lag_admin.media.bundle_enabled', \array_key_exists('JKMediaBundle', $container->getParameter('kernel.bundles')));
0 ignored issues
show
Bug introduced by
It seems like $container->getParameter('kernel.bundles') can also be of type boolean and double and integer and string; however, parameter $array of array_key_exists() does only seem to accept ArrayObject|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $container->setParameter('lag_admin.media.bundle_enabled', \array_key_exists('JKMediaBundle', /** @scrutinizer ignore-type */ $container->getParameter('kernel.bundles')));
Loading history...
39 3
        $container->setParameter('lag_admin.fields.mapping', $config['fields_mapping']);
40 3
    }
41
42 1
    public function getAlias(): string
43
    {
44 1
        return 'lag_admin';
45
    }
46
47 1
    public function prepend(ContainerBuilder $container): void
48
    {
49 1
        $container->prependExtensionConfig('knp_menu', [
50
            'twig' => [
51 1
                'template' => '@LAGAdmin/menu/menu-base.html.twig',
52
            ],
53
        ]);
54 1
        $container->prependExtensionConfig('twig', [
55 1
            'form_themes' => ['@LAGAdmin/form/fields.html.twig'],
56
        ]);
57 1
    }
58
}
59