ProviderCallbackPass::process()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 11
nc 3
nop 1
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