HMLBDDDBundle::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 6
Ratio 50 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 12
rs 8.8571
cc 5
eloc 7
nc 4
nop 0
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace HMLB\DDDBundle;
6
7
use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass;
8
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
9
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
10
use HMLB\DDDBundle\DependencyInjection\HMLBDDDExtension;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\HttpKernel\Bundle\Bundle;
13
use HMLB\DDDBundle\Doctrine\ORM\DBAL\Types\IdentityType as DBALIdType;
14
use HMLB\DDDBundle\Doctrine\ODM\MongoDB\Types\IdentityType as MongoIdType;
15
16
/**
17
 * HMLBDDDBundle.
18
 *
19
 * @author Hugues Maignol <[email protected]>
20
 */
21
class HMLBDDDBundle extends Bundle
22
{
23
    public function __construct()
24
    {
25
        $mongoType = '\Doctrine\ODM\MongoDB\Types\Type';
26 View Code Duplication
        if (class_exists($mongoType) && !call_user_func($mongoType.'::hasType', MongoIdType::NAME)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            call_user_func($mongoType.'::addType', MongoIdType::NAME, MongoIdType::class);
28
        }
29
30
        $DBALType = '\Doctrine\DBAL\Types\Type';
31 View Code Duplication
        if (class_exists($DBALType) && !call_user_func($DBALType.'::hasType', DBALIdType::NAME)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
            call_user_func($DBALType.'::addType', DBALIdType::NAME, DBALIdType::class);
33
        }
34
    }
35
36
    public function build(ContainerBuilder $container)
37
    {
38
        $this->addRegisterMappingsPass($container);
39
    }
40
41
    /**
42
     * @param ContainerBuilder $container
43
     */
44
    private function addRegisterMappingsPass(ContainerBuilder $container)
45
    {
46
        $mappings = [
47
            realpath(__DIR__.'/Resources/config/doctrine') => 'HMLB\DDD',
48
        ];
49
50
        if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
51
            $container->addCompilerPass(
52
                DoctrineOrmMappingsPass::createXmlMappingDriver(
53
                    $mappings,
54
                    ['fos_user.model_manager_name'],
55
                    'fos_user.backend_type_orm'
56
                )
57
            );
58
        }
59
60
        if (class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) {
61
            $container->addCompilerPass(
62
                DoctrineMongoDBMappingsPass::createXmlMappingDriver(
63
                    $mappings,
64
                    ['fos_user.model_manager_name'],
65
                    'fos_user.backend_type_mongodb'
66
                )
67
            );
68
        }
69
70
        if (class_exists('Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass')) {
71
            $container->addCompilerPass(
72
                DoctrineCouchDBMappingsPass::createXmlMappingDriver(
73
                    $mappings,
74
                    ['fos_user.model_manager_name'],
75
                    'fos_user.backend_type_couchdb'
76
                )
77
            );
78
        }
79
    }
80
81
    public function getContainerExtension()
82
    {
83
        return new HMLBDDDExtension();
84
    }
85
}
86