RemoveUnavailableServicesPass::process()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 6
eloc 10
nc 6
nop 1
1
<?php
2
3
namespace Knp\RadBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class RemoveUnavailableServicesPass implements CompilerPassInterface
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    public function process(ContainerBuilder $container)
14
    {
15
        foreach ($container->findTaggedServiceIds('remove-when-missing') as $id => $tags) {
16
            foreach ($tags as $tag) {
17
                if (!isset($tag['service'])) {
18
                    continue;
19
                }
20
21
                if ($container->hasDefinition($tag['service'])) {
22
                    continue;
23
                }
24
                if ($container->hasAlias($tag['service'])) {
25
                    continue;
26
                }
27
28
                $container->removeDefinition($id);
29
            }
30
        }
31
    }
32
}
33