Completed
Push — master ( 66ec7e...c9ec0a )
by Matze
07:32
created

SetDefinitionFileCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
rs 9.2
cc 4
eloc 9
nc 4
nop 1
crap 4.1755
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(priority=1)
13
 */
14
class SetDefinitionFileCompilerPass implements CompilerPassInterface
15
{
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    public function process(ContainerBuilder $container)
21
    {
22 2
        foreach ($container->getDefinitions() as $serviceId => $definition) {
23
            try {
24 2
                $reflection = new ReflectionClass($definition->getClass());
25
            } catch (ReflectionException $e) {
26
                continue;
27
            }
28
29 2
            $filename = $reflection->getFileName();
30 2
            if (!empty($filename)) {
31 2
                $definition->setFile($filename);
32
            }
33
        }
34 2
    }
35
}
36