Completed
Push — master ( 1b817e...6c15b7 )
by Jeroen
39:29
created

Compiler/KunstmaanTranslatorCompilerPass.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class KunstmaanTranslatorCompilerPass implements CompilerPassInterface
11
{
12
    public function process(ContainerBuilder $container)
13
    {
14
        $loaderRefs = array();
15
        $loaderAliases = array();
0 ignored issues
show
$loaderAliases is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
        $exporterRefs = array();
17
18
        foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
19
            $loaderRefs[$id] = new Reference($id);
20
            $loaders[$id][] = $attributes[0]['alias'];
21
            if (isset($attributes[0]['legacy-alias'])) {
22
                $loaders[$id][] = $attributes[0]['legacy-alias'];
23
            }
24
        }
25
26
        if ($container->hasDefinition('kunstmaan_translator.service.importer.importer')) {
27
            $definition = $container->getDefinition('kunstmaan_translator.service.importer.importer');
28
            foreach ($loaders as $id => $formats) {
29
                foreach ($formats as $format) {
30
                    $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
31
                }
32
            }
33
        }
34
35
        if ($container->hasDefinition('kunstmaan_translator.service.translator.translator')) {
36
            //Create custom ServiceLocator to inject in the translator
37
            $serviceIds = array_merge($loaderRefs, ['request_stack' => new Reference('request_stack')]);
38
            $serviceLocator = ServiceLocatorTagPass::register($container, $serviceIds);
39
40
            $container->getDefinition('kunstmaan_translator.service.translator.translator')
41
                ->replaceArgument(0, $serviceLocator)
42
                ->replaceArgument(3, $loaders);
43
        }
44
45
        // add all exporter into the translation exporter
46
        foreach ($container->findTaggedServiceIds('translation.exporter') as $id => $attributes) {
47
            $exporterRefs[$attributes[0]['alias']] = new Reference($id);
48
        }
49
50
        if ($container->hasDefinition('kunstmaan_translator.service.exporter.exporter')) {
51
            $container->getDefinition('kunstmaan_translator.service.exporter.exporter')->addMethodCall('setExporters', array($exporterRefs));
52
        }
53
    }
54
}
55