Completed
Push — master ( 0215a9...dbc4c0 )
by Christophe
01:38
created

IncenteevTranslationCheckerExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 39
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B loadInternal() 0 36 5
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\DependencyInjection;
4
5
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
6
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
class IncenteevTranslationCheckerExtension extends ConfigurableExtension
11
{
12 6
    public function loadInternal(array $config, ContainerBuilder $container)
13
    {
14 6
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
15 6
        $loader->load('services.xml');
16
17
        // supports autoconfiguration of extractors in Symfony 3.3+
18 6
        if (method_exists($container, 'registerForAutoconfiguration')) {
19 6
            $container->registerForAutoconfiguration('Incenteev\TranslationCheckerBundle\Translator\Extractor\ExtractorInterface')
20 6
                ->addTag('incenteev_translation_checker.extractor');
21
        }
22
23 6
        $dirs = array();
24 6
        $overridePath = '%%kernel.root_dir%%/Resources/%s/views';
25 6
        $registeredBundles = $container->getParameter('kernel.bundles');
26
27 6
        foreach ($config['extraction']['bundles'] as $bundle) {
28 2
            if (!isset($registeredBundles[$bundle])) {
29 1
                throw new \InvalidArgumentException(sprintf('The bundle %s is not registered in the kernel.', $bundle));
30
            }
31
32 1
            $reflection = new \ReflectionClass($registeredBundles[$bundle]);
33 1
            $dirs[] = dirname($reflection->getFilename()).'/Resources/views';
34 1
            $dirs[] = sprintf($overridePath, $bundle);
35
        }
36 5
        $dirs[] = '%kernel.root_dir%/Resources/views';
37
38 5
        $container->setParameter('incenteev_translation_checker.extractor.symfony.paths', $dirs);
39
40 5
        if (empty($config['extraction']['js']['paths'])) {
41 3
            $container->removeDefinition('incenteev_translation_checker.extractor.js');
42
        } else {
43 2
            $container->getDefinition('incenteev_translation_checker.extractor.js')
44 2
                ->replaceArgument(0, $config['extraction']['js']['paths'])
45 2
                ->replaceArgument(1, $config['extraction']['js']['default_domain']);
46
        }
47 5
    }
48
}
49