Completed
Pull Request — master (#4)
by Pavel
10:02
created

MappingCollectorPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 42
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 33 4
1
<?php
2
3
namespace Bankiru\Api\DependencyInjection\Compiler;
4
5
use Bankiru\Api\Doctrine\Mapping\Driver\YmlMetadataDriver;
6
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
11
12
class MappingCollectorPass implements CompilerPassInterface
13
{
14
15
    /**
16
     * You can modify the container here before it is dumped to PHP code.
17
     *
18
     * @param ContainerBuilder $container
19
     */
20 5
    public function process(ContainerBuilder $container)
21
    {
22 5
        if (!$container->hasDefinition('bankiru_api.chain_driver')) {
23
            return;
24
        }
25
26 5
        $driver = $container->getDefinition('bankiru_api.chain_driver');
27
28 5
        foreach ($container->getParameter('kernel.bundles') as $bundle) {
29 5
            $refl = new \ReflectionClass($bundle);
30 5
            $path = dirname($refl->getFileName()) . '/Resources/config/api/';
31
32 5
            if (!is_dir($path)) {
33 5
                continue;
34
            }
35
36 2
            $namespace = $refl->getNamespaceName() . '\Entity';
37
38 2
            $locatorDef = new Definition(
39 2
                SymfonyFileLocator::class,
40
                [
41
                    [
42 2
                        $path => $namespace,
43 2
                    ],
44 2
                    '.api.yml',
45 2
                    DIRECTORY_SEPARATOR,
46
                ]
47 2
            );
48 2
            $driverDef  = new Definition(YmlMetadataDriver::class, [$locatorDef]);
49
50 2
            $driver->addMethodCall('addDriver', [$driverDef, $namespace]);
51 5
        }
52 5
    }
53
}
54