Completed
Push — master ( 660942...00951d )
by Tobias
06:51
created

TranslationExtension::getAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\DefinitionDecorator;
17
use Symfony\Component\DependencyInjection\Reference;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
use Symfony\Component\DependencyInjection\Loader;
20
21
/**
22
 * This is the class that loads and manages your bundle configuration.
23
 *
24
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
25
 */
26
class TranslationExtension extends Extension
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function load(array $configs, ContainerBuilder $container)
32
    {
33 1
        $configuration = new Configuration($container);
34 1
        $config = $this->processConfiguration($configuration, $configs);
35 1
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36
37 1
        $loader->load('services.yml');
38 1
        $loader->load('extractors.yml');
39
40 1
        $container->setParameter('php_translation.locales', $config['locales']);
41 1
        $container->setParameter('php_translation.default_locale', isset($config['default_locale']) ? $config['default_locale'] : $container->getParameter('kernel.default_locale'));
42
43 1
        if ($config['webui']['enabled']) {
44 1
            $this->enableWebUi($container, $config);
0 ignored issues
show
Unused Code introduced by
The call to the method Translation\Bundle\Depen...xtension::enableWebUi() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
45 1
        }
46
47 1
        if ($config['fallback_translation']['enabled']) {
48
            $loader->load('auto_translation.yml');
49
            $this->enableFallbackAutoTranslator($container, $config);
50
        }
51
52 1
        foreach ($config['configs'] as $name => &$c) {
53
            if (empty($c['project_root'])) {
54
                $c['project_root'] = dirname($container->getParameter('kernel.root_dir'));
55
            }
56
57
            $def = new DefinitionDecorator('php_translation.storage.file.abstract');
58
            $def->replaceArgument(2, $c['output_dir']);
59
            $container->setDefinition('php_translation.storage.file.'.$name, $def);
60 1
        }
61
62 1
        $container->getDefinition('php_translation.configuration_manager')
63 1
            ->replaceArgument(0, $config['configs']);
64 1
    }
65
66 1
    private function enableWebUi(ContainerBuilder $container, $config)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68 1
    }
69
70
    private function enableFallbackAutoTranslator(ContainerBuilder $container, $config)
71
    {
72
        $externalTranslatorId = 'php_translation.translator_service.'.$config['fallback_translation']['service'];
73
        $externalTranslatorDef = $container->getDefinition($externalTranslatorId);
74
        $externalTranslatorDef->addTag('php_translation.external_translator');
75
        $externalTranslatorDef->addArgument(new Reference($config['http_client']));
76
        $externalTranslatorDef->addArgument(new Reference($config['message_factory']));
77
78
        $container->setParameter('php_translation.translator_service.api_key', $config['fallback_translation']['api_key']);
79
    }
80
81 1
    public function getAlias()
82
    {
83 1
        return 'translation';
84
    }
85
}
86