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 |
||
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 = []) |
||
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 = []) |
|
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 = []) |
|
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 = []) |
|
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 = []) |
|
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 = []) |
||
152 | } |
||
153 |
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.