ClientCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 8.1239

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 4
cts 11
cp 0.3636
rs 9.6
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 8.1239
1
<?php
2
3
namespace Freshcells\SoapClientBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ClientCompilerPass implements CompilerPassInterface
10
{
11
    const CLIENT_TAG = 'freshcells_soap_client.client';
12
13 3
    public function process(ContainerBuilder $container)
14
    {
15 3
        $clients = $container->findTaggedServiceIds(self::CLIENT_TAG);
16
17 3
        foreach ($clients as $clientId => $tags) {
18
            if (count($tags) > 1) {
19
                throw new \LogicException(sprintf('Clients should use a single \'%s\' tag', self::CLIENT_TAG));
20
            }
21
22
            $clientDefinition = $container->findDefinition($clientId);
23
            if (isset($tags[0]['no_dispatcher']) === false) {
24
                $clientDefinition->addMethodCall(
25
                    'setDispatcher',
26
                    [
27
                        new Reference($container->getParameter('freshcells_soap_client.event_dispatcher.service'))
28
                    ]
29
                );
30
            }
31
        }
32 3
    }
33
}
34