FindClassTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\DependencyInjection\Compiler;
6
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * @internal
11
 *
12
 * @author Marko Kunic <[email protected]>
13
 */
14
trait FindClassTrait
15
{
16
    private function getClass(ContainerBuilder $container, string $id): ?string
17
    {
18
        $definition = $container->getDefinition($id);
19
20
        //Entity can be a class or a parameter
21
        $class = $definition->getArgument(1); //1 is Entity
22
23
        if ($class[0] !== '%') {
24
            return $class;
25
        }
26
27
        if ($container->hasParameter($class = trim($class, '%'))) {
28
            return $container->getParameter($class);
29
        }
30
31
        throw new \LogicException(sprintf(
32
            'Service "%s" has a parameter "%s" as an argument but it is not found.',
33
            $id,
34
            $class
35
        ));
36
    }
37
}
38