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\AdminBundle\DependencyInjection\Compiler; |
||
4 | |||
5 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
||
6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
7 | use Symfony\Component\DependencyInjection\Reference; |
||
8 | |||
9 | /** |
||
10 | * This compiler pass makes it possible to add processors for the Kunstmaan logger |
||
11 | */ |
||
12 | View Code Duplication | class AddLogProcessorsCompilerPass implements CompilerPassInterface |
|
0 ignored issues
–
show
|
|||
13 | { |
||
14 | /** |
||
15 | * @param ContainerBuilder $container |
||
16 | */ |
||
17 | public function process(ContainerBuilder $container) |
||
18 | { |
||
19 | if (!$container->hasDefinition('kunstmaan_admin.logger')) { |
||
20 | return; |
||
21 | } |
||
22 | |||
23 | $definition = $container->getDefinition('kunstmaan_admin.logger'); |
||
24 | |||
25 | foreach ($container->findTaggedServiceIds('kunstmaan_admin.logger.processor') as $id => $tags) { |
||
26 | foreach ($tags as $tag) { |
||
27 | if (!empty($tag['method'])) { |
||
28 | $processor = array(new Reference($id), $tag['method']); |
||
29 | } else { |
||
30 | // If no method is defined, fallback to use __invoke |
||
31 | $processor = new Reference($id); |
||
32 | } |
||
33 | $definition->addMethodCall('pushProcessor', array($processor)); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.