DoctrineOrmMappingsPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 138
Duplicated Lines 20.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 28
loc 138
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A createXmlMappingDriver() 7 7 1
A createYamlMappingDriver() 7 7 1
A createPhpMappingDriver() 7 7 1
A createAnnotationMappingDriver() 7 7 1
A createStaticPhpMappingDriver() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
4
5
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Class for Symfony bundles to configure mappings for model classes not in the
11
 * auto-mapped folder.
12
 *
13
 * NOTE: alias is only supported by Symfony 2.6+ and will be ignored with older versions.
14
 */
15
class DoctrineOrmMappingsPass extends RegisterMappingsPass
16
{
17
    /**
18
     * You should not directly instantiate this class but use one of the
19
     * factory methods.
20
     *
21
     * @param Definition|Reference $driver            Driver DI definition or reference.
22
     * @param array                $namespaces        List of namespaces handled by $driver.
23
     * @param string[]             $managerParameters Ordered list of container parameters that
24
     *                                                could hold the manager name.
25
     *                                                doctrine.default_entity_manager is appended
26
     *                                                automatically.
27
     * @param string|false         $enabledParameter  If specified, the compiler pass only executes
28
     *                                                if this parameter is defined in the service
29
     *                                                container.
30
     * @param array                $aliasMap          Map of alias to namespace.
31
     */
32
    public function __construct($driver, array $namespaces, array $managerParameters, $enabledParameter = false, array $aliasMap = [])
33
    {
34
        $managerParameters[] = 'doctrine.default_entity_manager';
35
        parent::__construct(
36
            $driver,
37
            $namespaces,
38
            $managerParameters,
39
            'doctrine.orm.%s_metadata_driver',
40
            $enabledParameter,
41
            'doctrine.orm.%s_configuration',
42
            'addEntityNamespace',
43
            $aliasMap
44
        );
45
    }
46
47
    /**
48
     * @param array        $namespaces        Hashmap of directory path to namespace.
49
     * @param string[]     $managerParameters List of parameters that could which object manager name
50
     *                                        your bundle uses. This compiler pass will automatically
51
     *                                        append the parameter name for the default entity manager
52
     *                                        to this list.
53
     * @param string|false $enabledParameter  Service container parameter that must be present to
54
     *                                        enable the mapping. Set to false to not do any check,
55
     *                                        optional.
56
     * @param string[]     $aliasMap          Map of alias to namespace.
57
     *
58
     * @return self
59
     */
60 View Code Duplication
    public static function createXmlMappingDriver(array $namespaces, array $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62
        $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', [$namespaces, '.orm.xml']);
63
        $driver  = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', [$locator]);
64
65
        return new DoctrineOrmMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
66
    }
67
68
    /**
69
     * @param array        $namespaces        Hashmap of directory path to namespace
70
     * @param string[]     $managerParameters List of parameters that could which object manager name
71
     *                                        your bundle uses. This compiler pass will automatically
72
     *                                        append the parameter name for the default entity manager
73
     *                                        to this list.
74
     * @param string|false $enabledParameter  Service container parameter that must be present to
75
     *                                        enable the mapping. Set to false to not do any check,
76
     *                                        optional.
77
     * @param string[]     $aliasMap          Map of alias to namespace.
78
     *
79
     * @return self
80
     */
81 View Code Duplication
    public static function createYamlMappingDriver(array $namespaces, array $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
82
    {
83
        $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', [$namespaces, '.orm.yml']);
84
        $driver  = new Definition('Doctrine\ORM\Mapping\Driver\YamlDriver', [$locator]);
85
86
        return new DoctrineOrmMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
87
    }
88
89
    /**
90
     * @param array        $namespaces        Hashmap of directory path to namespace
91
     * @param string[]     $managerParameters List of parameters that could which object manager name
92
     *                                        your bundle uses. This compiler pass will automatically
93
     *                                        append the parameter name for the default entity manager
94
     *                                        to this list.
95
     * @param string|false $enabledParameter  Service container parameter that must be present to
96
     *                                        enable the mapping. Set to false to not do any check,
97
     *                                        optional.
98
     * @param string[]     $aliasMap          Map of alias to namespace.
99
     *
100
     * @return self
101
     */
102 View Code Duplication
    public static function createPhpMappingDriver(array $namespaces, array $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
103
    {
104
        $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', [$namespaces, '.php']);
105
        $driver  = new Definition('Doctrine\Common\Persistence\Mapping\Driver\PHPDriver', [$locator]);
106
107
        return new DoctrineOrmMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
108
    }
109
110
    /**
111
     * @param array        $namespaces        List of namespaces that are handled with annotation mapping
112
     * @param array        $directories       List of directories to look for annotated classes
113
     * @param string[]     $managerParameters List of parameters that could which object manager name
114
     *                                        your bundle uses. This compiler pass will automatically
115
     *                                        append the parameter name for the default entity manager
116
     *                                        to this list.
117
     * @param string|false $enabledParameter  Service container parameter that must be present to
118
     *                                        enable the mapping. Set to false to not do any check,
119
     *                                        optional.
120
     * @param string[]     $aliasMap          Map of alias to namespace.
121
     *
122
     * @return self
123
     */
124 View Code Duplication
    public static function createAnnotationMappingDriver(array $namespaces, array $directories, array $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
125
    {
126
        $reader = new Reference('annotation_reader');
127
        $driver = new Definition('Doctrine\ORM\Mapping\Driver\AnnotationDriver', [$reader, $directories]);
128
129
        return new DoctrineOrmMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
130
    }
131
132
    /**
133
     * @param array        $namespaces        List of namespaces that are handled with static php mapping
134
     * @param array        $directories       List of directories to look for static php mapping files
135
     * @param string[]     $managerParameters List of parameters that could which object manager name
136
     *                                        your bundle uses. This compiler pass will automatically
137
     *                                        append the parameter name for the default entity manager
138
     *                                        to this list.
139
     * @param string|false $enabledParameter  Service container parameter that must be present to
140
     *                                        enable the mapping. Set to false to not do any check,
141
     *                                        optional.
142
     * @param string[]     $aliasMap          Map of alias to namespace.
143
     *
144
     * @return self
145
     */
146
    public static function createStaticPhpMappingDriver(array $namespaces, array $directories, array $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
147
    {
148
        $driver = new Definition('Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver', [$directories]);
149
150
        return new DoctrineOrmMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
151
    }
152
}
153