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

SetDefinitionFileCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 0
cbo 2
dl 0
loc 30
ccs 13
cts 14
cp 0.9286
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 23 5
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