Completed
Push — l10n_master ( 6cb695...818918 )
by Kunstmaan
50:17 queued 35:37
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 9
    public function process(ContainerBuilder $container)
13
    {
14 9
        $loaderRefs = [];
15 9
        $loaderAliases = [];
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 9
        $exporterRefs = [];
17 9
        $loaders = [];
18
19 9
        foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
20 4
            $loaderRefs[$id] = new Reference($id);
21 4
            $loaders[$id][] = $attributes[0]['alias'];
22 4
            if (isset($attributes[0]['legacy-alias'])) {
23 4
                $loaders[$id][] = $attributes[0]['legacy-alias'];
24
            }
25
        }
26
27 9
        if ($container->hasDefinition('kunstmaan_translator.service.importer.importer')) {
28 4
            $definition = $container->getDefinition('kunstmaan_translator.service.importer.importer');
29 4
            foreach ($loaders as $id => $formats) {
30 4
                foreach ($formats as $format) {
31 4
                    $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
32
                }
33
            }
34
        }
35
36 9
        if ($container->hasDefinition('kunstmaan_translator.service.translator.translator')) {
37
            //Create custom ServiceLocator to inject in the translator
38 4
            $serviceIds = array_merge($loaderRefs, ['request_stack' => new Reference('request_stack')]);
39 4
            $serviceLocator = ServiceLocatorTagPass::register($container, $serviceIds);
40
41 4
            $container->getDefinition('kunstmaan_translator.service.translator.translator')
42 4
                ->replaceArgument(0, $serviceLocator)
43 4
                ->replaceArgument(3, $loaders);
44
        }
45
46
        // add all exporter into the translation exporter
47 9
        foreach ($container->findTaggedServiceIds('translation.exporter') as $id => $attributes) {
48 7
            $exporterRefs[$attributes[0]['alias']] = new Reference($id);
49
        }
50
51 9
        if ($container->hasDefinition('kunstmaan_translator.service.exporter.exporter')) {
52 7
            $container->getDefinition('kunstmaan_translator.service.exporter.exporter')->addMethodCall('setExporters', array($exporterRefs));
53
        }
54
55 9
        if ($container->has('translator.data_collector')) {
56
            $container->setAlias('translator.data_collector', 'kunstmaan_translator.datacollector');
57
        }
58 9
    }
59
}
60