ProviderCallbackPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 20 5
1
<?php
2
3
namespace DoS\SMSBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ProviderCallbackPass implements CompilerPassInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        $providerIds = $container->findTaggedServiceIds('dos.sms.provider');
17
        $callbackIds = $container->findTaggedServiceIds('dos.sms.provider_callback');
18
19
        foreach ($providerIds as $id => $tags) {
20
            $class = $container->getDefinition($id)->getClass();
21
            $class = $container->getParameter(str_replace('%', '', $class));
22
23
            if (!(new \ReflectionClass($class))->implementsInterface('DoS\SMSBundle\SMS\ProviderInterface')) {
24
                continue;
25
            }
26
27
            foreach ($callbackIds as $name => $attrs) {
28
                if ($tags[0]['alias'] == $attrs[0]['alias']) {
29
                    $container->getDefinition($id)->addMethodCall('setCallback', array(new Reference($name)));
30
                }
31
            }
32
        }
33
    }
34
}
35