Completed
Push — master ( 9ba770...8c603c )
by Christophe
13s
created

IncenteevTranslationCheckerExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B loadInternal() 0 28 4
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 4
    public function loadInternal(array $config, ContainerBuilder $container)
13
    {
14 4
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
15 4
        $loader->load('services.xml');
16
17
        // supports autoconfiguration of extractors in Symfony 3.3+
18 4
        if (method_exists($container, 'registerForAutoconfiguration')) {
19 4
            $container->registerForAutoconfiguration('Incenteev\TranslationCheckerBundle\Translator\Extractor\ExtractorInterface')
20 4
                ->addTag('incenteev_translation_checker.extractor');
21
        }
22
23 4
        $dirs = array();
24 4
        $overridePath = '%%kernel.root_dir%%/Resources/%s/views';
25 4
        $registeredBundles = $container->getParameter('kernel.bundles');
26
27 4
        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 3
        $dirs[] = '%kernel.root_dir%/Resources/views';
37
38 3
        $container->setParameter('incenteev_translation_checker.extractor.symfony.paths', $dirs);
39 3
    }
40
}
41