Completed
Pull Request — master (#18)
by Christophe
05:57 queued 01:08
created

IncenteevTranslationCheckerExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
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 33
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B loadInternal() 0 30 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 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 6
        $dirs = array();
18 6
        $overridePath = '%%kernel.root_dir%%/Resources/%s/views';
19 6
        $registeredBundles = $container->getParameter('kernel.bundles');
20
21 6
        foreach ($config['extraction']['bundles'] as $bundle) {
22 2
            if (!isset($registeredBundles[$bundle])) {
23 1
                throw new \InvalidArgumentException(sprintf('The bundle %s is not registered in the kernel.', $bundle));
24
            }
25
26 1
            $reflection = new \ReflectionClass($registeredBundles[$bundle]);
27 1
            $dirs[] = dirname($reflection->getFilename()).'/Resources/views';
28 1
            $dirs[] = sprintf($overridePath, $bundle);
29 5
        }
30 5
        $dirs[] = '%kernel.root_dir%/Resources/views';
31
32 5
        $container->setParameter('incenteev_translation_checker.extractor.symfony.paths', $dirs);
33
34 5
        if (empty($config['extraction']['js']['paths'])) {
35 3
            $container->removeDefinition('incenteev_translation_checker.extractor.js');
36 3
        } else {
37 2
            $container->getDefinition('incenteev_translation_checker.extractor.js')
38 2
                ->replaceArgument(0, $config['extraction']['js']['paths'])
39 2
                ->replaceArgument(1, $config['extraction']['js']['default_domain']);
40
        }
41 5
    }
42
}
43