Failed Conditions
Pull Request — 2.6 (#7119)
by
unknown
09:21
created

XmlDriver::loadMappingFile()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 4
nop 1
dl 0
loc 24
ccs 16
cts 16
cp 1
crap 7
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Mapping\Driver;
21
22
use SimpleXMLElement;
23
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
24
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;
25
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
26
use Doctrine\ORM\Mapping\MappingException;
27
use Doctrine\ORM\Mapping\ClassMetadata as Metadata;
28
29
/**
30
 * XmlDriver is a metadata driver that enables mapping through XML files.
31
 *
32
 * @license 	http://www.opensource.org/licenses/mit-license.php MIT
33
 * @link    	www.doctrine-project.org
34
 * @since   	2.0
35
 * @author		Benjamin Eberlei <[email protected]>
36
 * @author		Guilherme Blanco <[email protected]>
37
 * @author      Jonathan H. Wage <[email protected]>
38
 * @author      Roman Borschel <[email protected]>
39
 */
40
class XmlDriver extends FileDriver
41
{
42
    const DEFAULT_FILE_EXTENSION = '.dcm.xml';
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 44
    public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION)
48
    {
49 44
        parent::__construct($locator, $fileExtension);
50 44
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55 39
    public function loadMetadataForClass($className, ClassMetadata $metadata)
56
    {
57
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
58
        /* @var $xmlRoot SimpleXMLElement */
59 39
        $xmlRoot = $this->getElement($className);
60
61 37
        if ($xmlRoot->getName() == 'entity') {
62 36
            if (isset($xmlRoot['repository-class'])) {
63
                $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
0 ignored issues
show
Bug introduced by
The method setCustomRepositoryClass() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
                $metadata->/** @scrutinizer ignore-call */ 
64
                           setCustomRepositoryClass((string) $xmlRoot['repository-class']);
Loading history...
64
            }
65 36
            if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) {
66 36
                $metadata->markReadOnly();
0 ignored issues
show
Bug introduced by
The method markReadOnly() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
                $metadata->/** @scrutinizer ignore-call */ 
67
                           markReadOnly();
Loading history...
67
            }
68 8
        } else if ($xmlRoot->getName() == 'mapped-superclass') {
69 5
            $metadata->setCustomRepositoryClass(
70 5
                isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null
71
            );
72 5
            $metadata->isMappedSuperclass = true;
0 ignored issues
show
Bug introduced by
Accessing isMappedSuperclass on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
73 3
        } else if ($xmlRoot->getName() == 'embeddable') {
74 3
            $metadata->isEmbeddedClass = true;
0 ignored issues
show
Bug introduced by
Accessing isEmbeddedClass on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
75
        } else {
76
            throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
77
        }
78
79
        // Evaluate <entity...> attributes
80 37
        $primaryTable = [];
81
82 37
        if (isset($xmlRoot['table'])) {
83 16
            $primaryTable['name'] = (string) $xmlRoot['table'];
84
        }
85
86 37
        if (isset($xmlRoot['schema'])) {
87 1
            $primaryTable['schema'] = (string) $xmlRoot['schema'];
88
        }
89
90 37
        $metadata->setPrimaryTable($primaryTable);
0 ignored issues
show
Bug introduced by
The method setPrimaryTable() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        $metadata->/** @scrutinizer ignore-call */ 
91
                   setPrimaryTable($primaryTable);
Loading history...
91
92
        // Evaluate second level cache
93 37
        if (isset($xmlRoot->cache)) {
94 2
            $metadata->enableCache($this->cacheToArray($xmlRoot->cache));
0 ignored issues
show
Bug introduced by
The method enableCache() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
            $metadata->/** @scrutinizer ignore-call */ 
95
                       enableCache($this->cacheToArray($xmlRoot->cache));
Loading history...
95
        }
96
97
        // Evaluate named queries
98 37
        if (isset($xmlRoot->{'named-queries'})) {
99 4
            foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) {
100 4
                $metadata->addNamedQuery(
0 ignored issues
show
Bug introduced by
The method addNamedQuery() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
                $metadata->/** @scrutinizer ignore-call */ 
101
                           addNamedQuery(
Loading history...
101
                    [
102 4
                        'name'  => (string) $namedQueryElement['name'],
103 4
                        'query' => (string) $namedQueryElement['query']
104
                    ]
105
                );
106
            }
107
        }
108
109
        // Evaluate native named queries
110 37
        if (isset($xmlRoot->{'named-native-queries'})) {
111 3
            foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) {
112 3
                $metadata->addNamedNativeQuery(
0 ignored issues
show
Bug introduced by
The method addNamedNativeQuery() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

112
                $metadata->/** @scrutinizer ignore-call */ 
113
                           addNamedNativeQuery(
Loading history...
113
                    [
114 3
                        'name'              => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null,
115 3
                        'query'             => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null,
116 3
                        'resultClass'       => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null,
117 3
                        'resultSetMapping'  => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null,
118
                    ]
119
                );
120
            }
121
        }
122
123
        // Evaluate sql result set mapping
124 37
        if (isset($xmlRoot->{'sql-result-set-mappings'})) {
125 3
            foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) {
126 3
                $entities   = [];
127 3
                $columns    = [];
128 3
                foreach ($rsmElement as $entityElement) {
129
                    //<entity-result/>
130 3
                    if (isset($entityElement['entity-class'])) {
131
                        $entityResult = [
132 3
                            'fields'                => [],
133 3
                            'entityClass'           => (string) $entityElement['entity-class'],
134 3
                            'discriminatorColumn'   => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null,
135
                        ];
136
137 3
                        foreach ($entityElement as $fieldElement) {
138 3
                            $entityResult['fields'][] = [
139 3
                                'name'      => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null,
140 3
                                'column'    => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null,
141
                            ];
142
                        }
143
144 3
                        $entities[] = $entityResult;
145
                    }
146
147
                    //<column-result/>
148 3
                    if (isset($entityElement['name'])) {
149 3
                        $columns[] = [
150 3
                            'name' => (string) $entityElement['name'],
151
                        ];
152
                    }
153
                }
154
155 3
                $metadata->addSqlResultSetMapping(
0 ignored issues
show
Bug introduced by
The method addSqlResultSetMapping() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
                $metadata->/** @scrutinizer ignore-call */ 
156
                           addSqlResultSetMapping(
Loading history...
156
                    [
157 3
                        'name'          => (string) $rsmElement['name'],
158 3
                        'entities'      => $entities,
159 3
                        'columns'       => $columns
160
                    ]
161
                );
162
            }
163
        }
164
165 37
        if (isset($xmlRoot['inheritance-type'])) {
166 10
            $inheritanceType = (string) $xmlRoot['inheritance-type'];
167 10
            $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
0 ignored issues
show
Bug introduced by
The method setInheritanceType() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

167
            $metadata->/** @scrutinizer ignore-call */ 
168
                       setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
Loading history...
168
169 10
            if ($metadata->inheritanceType != Metadata::INHERITANCE_TYPE_NONE) {
0 ignored issues
show
Bug introduced by
Accessing inheritanceType on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
170
                // Evaluate <discriminator-column...>
171 10
                if (isset($xmlRoot->{'discriminator-column'})) {
172 7
                    $discrColumn = $xmlRoot->{'discriminator-column'};
173 7
                    $metadata->setDiscriminatorColumn(
0 ignored issues
show
Bug introduced by
The method setDiscriminatorColumn() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
                    $metadata->/** @scrutinizer ignore-call */ 
174
                               setDiscriminatorColumn(
Loading history...
174
                        [
175 7
                            'name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null,
176 7
                            'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string',
177 7
                            'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : 255,
178 7
                            'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null,
179 7
                            'strict' => isset($discrColumn['strict']) ? (bool) $discrColumn['strict'] : false
180
                        ]
181
                    );
182
                } else {
183 6
                    $metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]);
184
                }
185
186
                // Evaluate <discriminator-map...>
187 10
                if (isset($xmlRoot->{'discriminator-map'})) {
188 10
                    $map = [];
189 10
                    foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
190 10
                        $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
191
                    }
192 10
                    $metadata->setDiscriminatorMap($map);
0 ignored issues
show
Bug introduced by
The method setDiscriminatorMap() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

192
                    $metadata->/** @scrutinizer ignore-call */ 
193
                               setDiscriminatorMap($map);
Loading history...
193
                }
194
            }
195
        }
196
197
198
        // Evaluate <change-tracking-policy...>
199 37
        if (isset($xmlRoot['change-tracking-policy'])) {
200
            $metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_'
0 ignored issues
show
Bug introduced by
The method setChangeTrackingPolicy() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

200
            $metadata->/** @scrutinizer ignore-call */ 
201
                       setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_'
Loading history...
201
                . strtoupper((string) $xmlRoot['change-tracking-policy'])));
202
        }
203
204
        // Evaluate <indexes...>
205 37
        if (isset($xmlRoot->indexes)) {
206 4
            $metadata->table['indexes'] = [];
0 ignored issues
show
Bug introduced by
Accessing table on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
207 4
            foreach ($xmlRoot->indexes->index as $indexXml) {
208 4
                $index = ['columns' => explode(',', (string) $indexXml['columns'])];
209
210 4
                if (isset($indexXml['flags'])) {
211 1
                    $index['flags'] = explode(',', (string) $indexXml['flags']);
212
                }
213
214 4
                if (isset($indexXml->options)) {
215 1
                    $index['options'] = $this->_parseOptions($indexXml->options->children());
216
                }
217
218 4
                if (isset($indexXml['name'])) {
219 3
                    $metadata->table['indexes'][(string) $indexXml['name']] = $index;
220
                } else {
221 4
                    $metadata->table['indexes'][] = $index;
222
                }
223
            }
224
        }
225
226
        // Evaluate <unique-constraints..>
227 37
        if (isset($xmlRoot->{'unique-constraints'})) {
228 3
            $metadata->table['uniqueConstraints'] = [];
229 3
            foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) {
230 3
                $unique = ['columns' => explode(',', (string) $uniqueXml['columns'])];
231
232 3
                if (isset($uniqueXml->options)) {
233 3
                    $unique['options'] = $this->_parseOptions($uniqueXml->options->children());
234
                }
235
236 3
                if (isset($uniqueXml['name'])) {
237 3
                    $metadata->table['uniqueConstraints'][(string) $uniqueXml['name']] = $unique;
238
                } else {
239 3
                    $metadata->table['uniqueConstraints'][] = $unique;
240
                }
241
            }
242
        }
243
244 37
        if (isset($xmlRoot->options)) {
245 5
            $metadata->table['options'] = $this->_parseOptions($xmlRoot->options->children());
246
        }
247
248
        // The mapping assignment is done in 2 times as a bug might occurs on some php/xml lib versions
249
        // The internal SimpleXmlIterator get resetted, to this generate a duplicate field exception
250 37
        $mappings = [];
251
        // Evaluate <field ...> mappings
252 37
        if (isset($xmlRoot->field)) {
253 24
            foreach ($xmlRoot->field as $fieldMapping) {
254 24
                $mapping = $this->columnToArray($fieldMapping);
255
256 24
                if (isset($mapping['version'])) {
257 3
                    $metadata->setVersionMapping($mapping);
0 ignored issues
show
Bug introduced by
The method setVersionMapping() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

257
                    $metadata->/** @scrutinizer ignore-call */ 
258
                               setVersionMapping($mapping);
Loading history...
258 3
                    unset($mapping['version']);
259
                }
260
261 24
                $metadata->mapField($mapping);
0 ignored issues
show
Bug introduced by
The method mapField() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

261
                $metadata->/** @scrutinizer ignore-call */ 
262
                           mapField($mapping);
Loading history...
262
            }
263
        }
264
265 37
        if (isset($xmlRoot->embedded)) {
266 3
            foreach ($xmlRoot->embedded as $embeddedMapping) {
267 3
                $columnPrefix = isset($embeddedMapping['column-prefix'])
268 3
                    ? (string) $embeddedMapping['column-prefix']
269 3
                    : null;
270
271 3
                $useColumnPrefix = isset($embeddedMapping['use-column-prefix'])
272 2
                    ? $this->evaluateBoolean($embeddedMapping['use-column-prefix'])
273 3
                    : true;
274
275
                $mapping = [
276 3
                    'fieldName' => (string) $embeddedMapping['name'],
277 3
                    'class' => (string) $embeddedMapping['class'],
278 3
                    'columnPrefix' => $useColumnPrefix ? $columnPrefix : false
279
                ];
280
281 3
                $metadata->mapEmbedded($mapping);
0 ignored issues
show
Bug introduced by
The method mapEmbedded() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

281
                $metadata->/** @scrutinizer ignore-call */ 
282
                           mapEmbedded($mapping);
Loading history...
282
            }
283
        }
284
285 37
        foreach ($mappings as $mapping) {
286
            if (isset($mapping['version'])) {
287
                $metadata->setVersionMapping($mapping);
288
            }
289
290
            $metadata->mapField($mapping);
291
        }
292
293
        // Evaluate <id ...> mappings
294 37
        $associationIds = [];
295 37
        foreach ($xmlRoot->id as $idElement) {
296 34
            if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) {
297 2
                $associationIds[(string) $idElement['name']] = true;
298 2
                continue;
299
            }
300
301
            $mapping = [
302 33
                'id' => true,
303 33
                'fieldName' => (string) $idElement['name']
304
            ];
305
306 33
            if (isset($idElement['type'])) {
307 21
                $mapping['type'] = (string) $idElement['type'];
308
            }
309
310 33
            if (isset($idElement['length'])) {
311 3
                $mapping['length'] = (string) $idElement['length'];
312
            }
313
314 33
            if (isset($idElement['column'])) {
315 24
                $mapping['columnName'] = (string) $idElement['column'];
316
            }
317
318 33
            if (isset($idElement['column-definition'])) {
319 1
                $mapping['columnDefinition'] = (string) $idElement['column-definition'];
320
            }
321
322 33
            if (isset($idElement->options)) {
323 3
                $mapping['options'] = $this->_parseOptions($idElement->options->children());
324
            }
325
326 33
            $metadata->mapField($mapping);
327
328 33
            if (isset($idElement->generator)) {
329 32
                $strategy = isset($idElement->generator['strategy']) ?
330 32
                        (string) $idElement->generator['strategy'] : 'AUTO';
331 32
                $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
0 ignored issues
show
Bug introduced by
The method setIdGeneratorType() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

331
                $metadata->/** @scrutinizer ignore-call */ 
332
                           setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
Loading history...
332 32
                    . $strategy));
333
            }
334
335
            // Check for SequenceGenerator/TableGenerator definition
336 33
            if (isset($idElement->{'sequence-generator'})) {
337 3
                $seqGenerator = $idElement->{'sequence-generator'};
338 3
                $metadata->setSequenceGeneratorDefinition(
0 ignored issues
show
Bug introduced by
The method setSequenceGeneratorDefinition() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

338
                $metadata->/** @scrutinizer ignore-call */ 
339
                           setSequenceGeneratorDefinition(
Loading history...
339
                    [
340 3
                        'sequenceName' => (string) $seqGenerator['sequence-name'],
341 3
                        'allocationSize' => (string) $seqGenerator['allocation-size'],
342 3
                        'initialValue' => (string) $seqGenerator['initial-value']
343
                    ]
344
                );
345 30
            } else if (isset($idElement->{'custom-id-generator'})) {
346 2
                $customGenerator = $idElement->{'custom-id-generator'};
347 2
                $metadata->setCustomGeneratorDefinition(
0 ignored issues
show
Bug introduced by
The method setCustomGeneratorDefinition() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

347
                $metadata->/** @scrutinizer ignore-call */ 
348
                           setCustomGeneratorDefinition(
Loading history...
348
                    [
349 2
                        'class' => (string) $customGenerator['class']
350
                    ]
351
                );
352 28
            } else if (isset($idElement->{'table-generator'})) {
353 33
                throw MappingException::tableIdGeneratorNotImplemented($className);
354
            }
355
        }
356
357
        // Evaluate <one-to-one ...> mappings
358 37
        if (isset($xmlRoot->{'one-to-one'})) {
359 8
            foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) {
360
                $mapping = [
361 8
                    'fieldName' => (string) $oneToOneElement['field'],
362 8
                    'targetEntity' => (string) $oneToOneElement['target-entity']
363
                ];
364
365 8
                if (isset($associationIds[$mapping['fieldName']])) {
366
                    $mapping['id'] = true;
367
                }
368
369 8
                if (isset($oneToOneElement['fetch'])) {
370 2
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $oneToOneElement['fetch']);
371
                }
372
373 8
                if (isset($oneToOneElement['mapped-by'])) {
374 2
                    $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by'];
375
                } else {
376 8
                    if (isset($oneToOneElement['inversed-by'])) {
377 8
                        $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by'];
378
                    }
379 8
                    $joinColumns = [];
380
381 8
                    if (isset($oneToOneElement->{'join-column'})) {
382 7
                        $joinColumns[] = $this->joinColumnToArray($oneToOneElement->{'join-column'});
383 1
                    } else if (isset($oneToOneElement->{'join-columns'})) {
384 1
                        foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
385 1
                            $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
386
                        }
387
                    }
388
389 8
                    $mapping['joinColumns'] = $joinColumns;
390
                }
391
392 8
                if (isset($oneToOneElement->cascade)) {
393 6
                    $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
394
                }
395
396 8
                if (isset($oneToOneElement['orphan-removal'])) {
397 3
                    $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToOneElement['orphan-removal']);
398
                }
399
400
                // Evaluate second level cache
401 8
                if (isset($oneToOneElement->cache)) {
402
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($oneToOneElement->cache));
0 ignored issues
show
Bug introduced by
The method getAssociationCacheDefaults() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. Did you maybe mean getAssociationNames()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

402
                    /** @scrutinizer ignore-call */ 
403
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($oneToOneElement->cache));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
403
                }
404
405 8
                $metadata->mapOneToOne($mapping);
0 ignored issues
show
Bug introduced by
The method mapOneToOne() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

405
                $metadata->/** @scrutinizer ignore-call */ 
406
                           mapOneToOne($mapping);
Loading history...
406
            }
407
        }
408
409
        // Evaluate <one-to-many ...> mappings
410 37
        if (isset($xmlRoot->{'one-to-many'})) {
411 8
            foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) {
412
                $mapping = [
413 8
                    'fieldName' => (string) $oneToManyElement['field'],
414 8
                    'targetEntity' => (string) $oneToManyElement['target-entity'],
415 8
                    'mappedBy' => (string) $oneToManyElement['mapped-by']
416
                ];
417
418 8
                if (isset($oneToManyElement['fetch'])) {
419 2
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']);
420
                }
421
422 8
                if (isset($oneToManyElement->cascade)) {
423 6
                    $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
424
                }
425
426 8
                if (isset($oneToManyElement['orphan-removal'])) {
427 6
                    $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToManyElement['orphan-removal']);
428
                }
429
430 8
                if (isset($oneToManyElement->{'order-by'})) {
431 6
                    $orderBy = [];
432 6
                    foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
433 6
                        $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
434
                    }
435 6
                    $mapping['orderBy'] = $orderBy;
436
                }
437
438 8
                if (isset($oneToManyElement['index-by'])) {
439 3
                    $mapping['indexBy'] = (string) $oneToManyElement['index-by'];
440 5
                } else if (isset($oneToManyElement->{'index-by'})) {
441
                    throw new \InvalidArgumentException("<index-by /> is not a valid tag");
442
                }
443
444
                // Evaluate second level cache
445 8
                if (isset($oneToManyElement->cache)) {
446 1
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($oneToManyElement->cache));
447
                }
448
449 8
                $metadata->mapOneToMany($mapping);
0 ignored issues
show
Bug introduced by
The method mapOneToMany() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

449
                $metadata->/** @scrutinizer ignore-call */ 
450
                           mapOneToMany($mapping);
Loading history...
450
            }
451
        }
452
453
        // Evaluate <many-to-one ...> mappings
454 37
        if (isset($xmlRoot->{'many-to-one'})) {
455 8
            foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) {
456
                $mapping = [
457 8
                    'fieldName' => (string) $manyToOneElement['field'],
458 8
                    'targetEntity' => (string) $manyToOneElement['target-entity']
459
                ];
460
461 8
                if (isset($associationIds[$mapping['fieldName']])) {
462 2
                    $mapping['id'] = true;
463
                }
464
465 8
                if (isset($manyToOneElement['fetch'])) {
466 1
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $manyToOneElement['fetch']);
467
                }
468
469 8
                if (isset($manyToOneElement['inversed-by'])) {
470 1
                    $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by'];
471
                }
472
473 8
                $joinColumns = [];
474
475 8
                if (isset($manyToOneElement->{'join-column'})) {
476 5
                    $joinColumns[] = $this->joinColumnToArray($manyToOneElement->{'join-column'});
477 3
                } else if (isset($manyToOneElement->{'join-columns'})) {
478 2
                    foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
479 2
                        $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
480
                    }
481
                }
482
483 8
                $mapping['joinColumns'] = $joinColumns;
484
485 8
                if (isset($manyToOneElement->cascade)) {
486 2
                    $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
487
                }
488
489
                // Evaluate second level cache
490 8
                if (isset($manyToOneElement->cache)) {
491 1
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($manyToOneElement->cache));
492
                }
493
494 8
                $metadata->mapManyToOne($mapping);
0 ignored issues
show
Bug introduced by
The method mapManyToOne() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

494
                $metadata->/** @scrutinizer ignore-call */ 
495
                           mapManyToOne($mapping);
Loading history...
495
496
            }
497
        }
498
499
        // Evaluate <many-to-many ...> mappings
500 36
        if (isset($xmlRoot->{'many-to-many'})) {
501 12
            foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) {
502
                $mapping = [
503 12
                    'fieldName' => (string) $manyToManyElement['field'],
504 12
                    'targetEntity' => (string) $manyToManyElement['target-entity']
505
                ];
506
507 12
                if (isset($manyToManyElement['fetch'])) {
508 3
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $manyToManyElement['fetch']);
509
                }
510
511 12
                if (isset($manyToManyElement['orphan-removal'])) {
512
                    $mapping['orphanRemoval'] = $this->evaluateBoolean($manyToManyElement['orphan-removal']);
513
                }
514
515 12
                if (isset($manyToManyElement['mapped-by'])) {
516 2
                    $mapping['mappedBy'] = (string) $manyToManyElement['mapped-by'];
517 10
                } else if (isset($manyToManyElement->{'join-table'})) {
518 8
                    if (isset($manyToManyElement['inversed-by'])) {
519 2
                        $mapping['inversedBy'] = (string) $manyToManyElement['inversed-by'];
520
                    }
521
522 8
                    $joinTableElement = $manyToManyElement->{'join-table'};
523
                    $joinTable = [
524 8
                        'name' => (string) $joinTableElement['name']
525
                    ];
526
527 8
                    if (isset($joinTableElement['schema'])) {
528
                        $joinTable['schema'] = (string) $joinTableElement['schema'];
529
                    }
530
531 8
                    foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
532 8
                        $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
533
                    }
534
535 8
                    foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
536 8
                        $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
537
                    }
538
539 8
                    $mapping['joinTable'] = $joinTable;
540
                }
541
542 12
                if (isset($manyToManyElement->cascade)) {
543 8
                    $mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade);
544
                }
545
546 12
                if (isset($manyToManyElement->{'order-by'})) {
547
                    $orderBy = [];
548
                    foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
549
                        $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
550
                    }
551
                    $mapping['orderBy'] = $orderBy;
552
                }
553
554 12
                if (isset($manyToManyElement['index-by'])) {
555
                    $mapping['indexBy'] = (string) $manyToManyElement['index-by'];
556 12
                } else if (isset($manyToManyElement->{'index-by'})) {
557
                    throw new \InvalidArgumentException("<index-by /> is not a valid tag");
558
                }
559
560
                // Evaluate second level cache
561 12
                if (isset($manyToManyElement->cache)) {
562
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($manyToManyElement->cache));
563
                }
564
565 12
                $metadata->mapManyToMany($mapping);
0 ignored issues
show
Bug introduced by
The method mapManyToMany() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

565
                $metadata->/** @scrutinizer ignore-call */ 
566
                           mapManyToMany($mapping);
Loading history...
566
            }
567
        }
568
569
        // Evaluate association-overrides
570 36
        if (isset($xmlRoot->{'attribute-overrides'})) {
571 2
            foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) {
572 2
                $fieldName = (string) $overrideElement['name'];
573 2
                foreach ($overrideElement->field as $field) {
574 2
                    $mapping = $this->columnToArray($field);
575 2
                    $mapping['fieldName'] = $fieldName;
576 2
                    $metadata->setAttributeOverride($fieldName, $mapping);
0 ignored issues
show
Bug introduced by
The method setAttributeOverride() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

576
                    $metadata->/** @scrutinizer ignore-call */ 
577
                               setAttributeOverride($fieldName, $mapping);
Loading history...
577
                }
578
            }
579
        }
580
581
        // Evaluate association-overrides
582 36
        if (isset($xmlRoot->{'association-overrides'})) {
583 4
            foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) {
584 4
                $fieldName  = (string) $overrideElement['name'];
585 4
                $override   = [];
586
587
                // Check for join-columns
588 4
                if (isset($overrideElement->{'join-columns'})) {
589 2
                    $joinColumns = [];
590 2
                    foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
591 2
                        $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
592
                    }
593 2
                    $override['joinColumns'] = $joinColumns;
594
                }
595
596
                // Check for join-table
597 4
                if ($overrideElement->{'join-table'}) {
598 2
                    $joinTable          = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $joinTable is dead and can be removed.
Loading history...
599 2
                    $joinTableElement   = $overrideElement->{'join-table'};
600
601
                    $joinTable = [
602 2
                        'name'      => (string) $joinTableElement['name'],
603 2
                        'schema'    => (string) $joinTableElement['schema']
604
                    ];
605
606 2
                    if (isset($joinTableElement->{'join-columns'})) {
607 2
                        foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
608 2
                            $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
609
                        }
610
                    }
611
612 2
                    if (isset($joinTableElement->{'inverse-join-columns'})) {
613 2
                        foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
614 2
                            $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
615
                        }
616
                    }
617
618 2
                    $override['joinTable'] = $joinTable;
619
                }
620
621
                // Check for inversed-by
622 4
                if (isset($overrideElement->{'inversed-by'})) {
623 1
                    $override['inversedBy'] = (string) $overrideElement->{'inversed-by'}['name'];
624
                }
625
626
                // Check for `fetch`
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
627 4
                if (isset($overrideElement['fetch'])) {
628 1
                    $override['fetch'] = constant(Metadata::class . '::FETCH_' . (string) $overrideElement['fetch']);
629
                }
630
631 4
                $metadata->setAssociationOverride($fieldName, $override);
0 ignored issues
show
Bug introduced by
The method setAssociationOverride() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

631
                $metadata->/** @scrutinizer ignore-call */ 
632
                           setAssociationOverride($fieldName, $override);
Loading history...
632
            }
633
        }
634
635
        // Evaluate <lifecycle-callbacks...>
636 36
        if (isset($xmlRoot->{'lifecycle-callbacks'})) {
637 5
            foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
638 5
                $metadata->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string) $lifecycleCallback['type']));
0 ignored issues
show
Bug introduced by
The method addLifecycleCallback() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

638
                $metadata->/** @scrutinizer ignore-call */ 
639
                           addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string) $lifecycleCallback['type']));
Loading history...
639
            }
640
        }
641
642
        // Evaluate entity listener
643 36
        if (isset($xmlRoot->{'entity-listeners'})) {
644 6
            foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) {
645 6
                $className = (string) $listenerElement['class'];
646
                // Evaluate the listener using naming convention.
647 6
                if ($listenerElement->count() === 0) {
648 2
                    EntityListenerBuilder::bindEntityListener($metadata, $className);
649
650 2
                    continue;
651
                }
652
653 4
                foreach ($listenerElement as $callbackElement) {
654 4
                    $eventName   = (string) $callbackElement['type'];
655 4
                    $methodName  = (string) $callbackElement['method'];
656
657 4
                    $metadata->addEntityListener($eventName, $className, $methodName);
0 ignored issues
show
Bug introduced by
The method addEntityListener() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

657
                    $metadata->/** @scrutinizer ignore-call */ 
658
                               addEntityListener($eventName, $className, $methodName);
Loading history...
658
                }
659
            }
660
        }
661 36
    }
662
663
    /**
664
     * Parses (nested) option elements.
665
     *
666
     * @param SimpleXMLElement $options The XML element.
667
     *
668
     * @return array The options array.
669
     */
670 6
    private function _parseOptions(SimpleXMLElement $options)
671
    {
672 6
        $array = [];
673
674
        /* @var $option SimpleXMLElement */
675 6
        foreach ($options as $option) {
676 6
            if ($option->count()) {
677 5
                $value = $this->_parseOptions($option->children());
678
            } else {
679 6
                $value = (string) $option;
680
            }
681
682 6
            $attributes = $option->attributes();
683
684 6
            if (isset($attributes->name)) {
685 6
                $nameAttribute = (string) $attributes->name;
686 6
                $array[$nameAttribute] = in_array($nameAttribute, ['unsigned', 'fixed'])
687 5
                    ? $this->evaluateBoolean($value)
688 6
                    : $value;
689
            } else {
690 6
                $array[] = $value;
691
            }
692
        }
693
694 6
        return $array;
695
    }
696
697
    /**
698
     * Constructs a joinColumn mapping array based on the information
699
     * found in the given SimpleXMLElement.
700
     *
701
     * @param SimpleXMLElement $joinColumnElement The XML element.
702
     *
703
     * @return array The mapping array.
704
     */
705 14
    private function joinColumnToArray(SimpleXMLElement $joinColumnElement)
706
    {
707
        $joinColumn = [
708 14
            'name' => (string) $joinColumnElement['name'],
709 14
            'referencedColumnName' => (string) $joinColumnElement['referenced-column-name']
710
        ];
711
712 14
        if (isset($joinColumnElement['unique'])) {
713 4
            $joinColumn['unique'] = $this->evaluateBoolean($joinColumnElement['unique']);
714
        }
715
716 14
        if (isset($joinColumnElement['nullable'])) {
717 6
            $joinColumn['nullable'] = $this->evaluateBoolean($joinColumnElement['nullable']);
718
        }
719
720 14
        if (isset($joinColumnElement['on-delete'])) {
721 6
            $joinColumn['onDelete'] = (string) $joinColumnElement['on-delete'];
722
        }
723
724 14
        if (isset($joinColumnElement['column-definition'])) {
725 5
            $joinColumn['columnDefinition'] = (string) $joinColumnElement['column-definition'];
726
        }
727
728 14
        return $joinColumn;
729
    }
730
731
     /**
732
     * Parses the given field as array.
733
     *
734
     * @param SimpleXMLElement $fieldMapping
735
     *
736
     * @return array
737
     */
738 24
    private function columnToArray(SimpleXMLElement $fieldMapping)
739
    {
740
        $mapping = [
741 24
            'fieldName' => (string) $fieldMapping['name'],
742
        ];
743
744 24
        if (isset($fieldMapping['type'])) {
745 20
            $mapping['type'] = (string) $fieldMapping['type'];
746
        }
747
748 24
        if (isset($fieldMapping['column'])) {
749 16
            $mapping['columnName'] = (string) $fieldMapping['column'];
750
        }
751
752 24
        if (isset($fieldMapping['length'])) {
753 11
            $mapping['length'] = (int) $fieldMapping['length'];
754
        }
755
756 24
        if (isset($fieldMapping['precision'])) {
757 1
            $mapping['precision'] = (int) $fieldMapping['precision'];
758
        }
759
760 24
        if (isset($fieldMapping['scale'])) {
761 1
            $mapping['scale'] = (int) $fieldMapping['scale'];
762
        }
763
764 24
        if (isset($fieldMapping['unique'])) {
765 10
            $mapping['unique'] = $this->evaluateBoolean($fieldMapping['unique']);
766
        }
767
768 24
        if (isset($fieldMapping['nullable'])) {
769 9
            $mapping['nullable'] = $this->evaluateBoolean($fieldMapping['nullable']);
770
        }
771
772 24
        if (isset($fieldMapping['version']) && $fieldMapping['version']) {
773 3
            $mapping['version'] = $this->evaluateBoolean($fieldMapping['version']);
774
        }
775
776 24
        if (isset($fieldMapping['column-definition'])) {
777 6
            $mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
778
        }
779
780 24
        if (isset($fieldMapping->options)) {
781 5
            $mapping['options'] = $this->_parseOptions($fieldMapping->options->children());
782
        }
783
784 24
        return $mapping;
785
    }
786
787
    /**
788
     * Parse / Normalize the cache configuration
789
     *
790
     * @param SimpleXMLElement $cacheMapping
791
     *
792
     * @return array
793
     */
794 2
    private function cacheToArray(SimpleXMLElement $cacheMapping)
795
    {
796 2
        $region = isset($cacheMapping['region']) ? (string) $cacheMapping['region'] : null;
797 2
        $usage  = isset($cacheMapping['usage']) ? strtoupper($cacheMapping['usage']) : null;
798
799 2
        if ($usage && ! defined('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $usage)) {
800
            throw new \InvalidArgumentException(sprintf('Invalid cache usage "%s"', $usage));
801
        }
802
803 2
        if ($usage) {
804 2
            $usage = constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $usage);
805
        }
806
807
        return [
808 2
            'usage'  => $usage,
809 2
            'region' => $region,
810
        ];
811
    }
812
813
    /**
814
     * Gathers a list of cascade options found in the given cascade element.
815
     *
816
     * @param SimpleXMLElement $cascadeElement The cascade element.
817
     *
818
     * @return array The list of cascade options.
819
     */
820 8
    private function _getCascadeMappings(SimpleXMLElement $cascadeElement)
821
    {
822 8
        $cascades = [];
823
        /* @var $action SimpleXmlElement */
824 8
        foreach ($cascadeElement->children() as $action) {
825
            // According to the JPA specifications, XML uses "cascade-persist"
826
            // instead of "persist". Here, both variations
827
            // are supported because both YAML and Annotation use "persist"
828
            // and we want to make sure that this driver doesn't need to know
829
            // anything about the supported cascading actions
830 8
            $cascades[] = str_replace('cascade-', '', $action->getName());
831
        }
832
833 8
        return $cascades;
834
    }
835
836
    /**
837
     * {@inheritDoc}
838
     */
839 39
    protected function loadMappingFile($file)
840
    {
841 39
        $result = [];
842
        // Note: we do not use `simplexml_load_file()` because of https://bugs.php.net/bug.php?id=62577
843 39
        $xmlElement = simplexml_load_string(file_get_contents($file));
844
845 39
        if (isset($xmlElement->entity)) {
846 37
            foreach ($xmlElement->entity as $entityElement) {
847 37
                $entityName = (string) $entityElement['name'];
848 37
                $result[$entityName] = $entityElement;
849
            }
850 9
        } else if (isset($xmlElement->{'mapped-superclass'})) {
851 5
            foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) {
852 5
                $className = (string) $mappedSuperClass['name'];
853 5
                $result[$className] = $mappedSuperClass;
854
            }
855 4
        } else if (isset($xmlElement->embeddable)) {
856 3
            foreach ($xmlElement->embeddable as $embeddableElement) {
857 3
                $embeddableName = (string) $embeddableElement['name'];
858 3
                $result[$embeddableName] = $embeddableElement;
859
            }
860
        }
861
862 39
        return $result;
863
    }
864
865
    /**
866
     * @param mixed $element
867
     *
868
     * @return bool
869
     */
870 14
    protected function evaluateBoolean($element)
871
    {
872 14
        $flag = (string) $element;
873
874 14
        return ($flag == "true" || $flag == "1");
875
    }
876
}
877