AlisterReservedNamesExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A collectAllNames() 0 9 1
A load() 0 11 1
1
<?php
2
namespace Alister\ReservedNamesBundle\DependencyInjection;
3
4
use Symfony\Component\Config\FileLocator;
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Loader;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
9
/**
10
 * This is the class that loads and manages your bundle configuration.
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
13
 */
14
class AlisterReservedNamesExtension extends Extension
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function load(array $configs, ContainerBuilder $container)
20
    {
21
        $configuration = new Configuration();
22
        $config = $this->processConfiguration($configuration, $configs);
23
24
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25
        $loader->load('services.yml');
26
27
        $container->setParameter(
28
            $this->getAlias().'.names',
29
            $this->collectAllNames($config['names'])
30
        );
31
    }
32
33
    public function collectAllNames($appNames = [])
34
    {
35
        $appNames = array_fill_keys($appNames, 1);
36
        $appNames = array_change_key_case($appNames, CASE_LOWER);
37
38
        $path = new FileLocator(__DIR__.'/../Resources/config/');
39
        $cfgNames = require $path->locate('reserved_names.php');
40
41
        return array_merge($cfgNames, $appNames);
42
    }
43
}
44