Completed
Pull Request — master (#10)
by Matze
07:31
created

SetDefinitionFileCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.0091

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 23
ccs 13
cts 14
cp 0.9286
rs 8.5907
cc 5
eloc 13
nc 5
nop 1
crap 5.0091
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use ReflectionClass;
7
use ReflectionException;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
11
/**
12
 * @CompilerPass
13
 */
14
class SetDefinitionFileCompilerPass implements CompilerPassInterface
15
{
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 5
    public function process(ContainerBuilder $container)
21
    {
22 5
        foreach ($container->getServiceIds() as $serviceId) {
23 5
            if (!$container->hasDefinition($serviceId)) {
24 1
                continue;
25
            }
26
27 4
            $definition = $container->getDefinition($serviceId);
28
29
            try {
30 4
                $reflection = new ReflectionClass($definition->getClass());
31 4
            } catch (ReflectionException $e) {
32 3
                continue;
33
            }
34
35 3
            $filename = $reflection->getFileName();
36 3
            if (empty($filename)) {
37
                continue;
38
            }
39
40 3
            $definition->setFile($filename);
41 5
        }
42 5
    }
43
}
44