ResponseHandlerCompilerPass::process()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 13
nc 6
nop 1
dl 0
loc 21
ccs 14
cts 14
cp 1
crap 6
rs 9.2222
c 1
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\DependencyInjection\CompilerPass;
4
5
use LAG\SmokerBundle\Contracts\Response\Handler\ResponseHandlerInterface;
6
use LAG\SmokerBundle\Response\Registry\ResponseHandlerRegistry;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
class ResponseHandlerCompilerPass implements CompilerPassInterface
12
{
13 2
    public function process(ContainerBuilder $container)
14
    {
15 2
        if (!$container->hasDefinition(ResponseHandlerRegistry::class)) {
16 1
            return;
17
        }
18 1
        $registry = $container->getDefinition(ResponseHandlerRegistry::class);
19
20 1
        foreach ($container->getDefinitions() as $serviceId => $definition) {
21 1
            if (null === $definition->getClass()) {
22 1
                continue;
23
            }
24
25 1
            if (!class_exists($definition->getClass())) {
26 1
                continue;
27
            }
28 1
            $implements = class_implements($definition->getClass());
29
30 1
            if (in_array(ResponseHandlerInterface::class, $implements)) {
31 1
                $registry->addMethodCall('add', [
32 1
                    $serviceId,
33 1
                    new Reference($serviceId),
34
                ]);
35
            }
36
        }
37 1
    }
38
}
39