Completed
Push — master ( 150272...5e1cd2 )
by Matze
14:28 queued 09:42
created

SetDefinitionFileCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 0
cbo 2
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 4
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 4
    public function process(ContainerBuilder $container)
21
    {
22 4
        foreach ($container->getDefinitions() as $serviceId => $definition) {
23
            try {
24 4
                $reflection = new ReflectionClass($definition->getClass());
25 1
            } catch (ReflectionException $e) {
26 1
                continue;
27
            }
28
29 3
            $filename = $reflection->getFileName();
30 3
            if (!empty($filename)) {
31 3
                $definition->setFile($filename);
32
            }
33
        }
34 4
    }
35
}
36