Failed Conditions
Pull Request — 2.6 (#7180)
by Ben
11:16
created

XmlDriver::_parseOptions()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 7
nop 1
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 5
rs 8.439
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
                        ]
180
                    );
181
                } else {
182 6
                    $metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]);
183
                }
184
185
                // Evaluate <discriminator-map...>
186 10
                if (isset($xmlRoot->{'discriminator-map'})) {
187 10
                    $map = [];
188 10
                    foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
189 10
                        $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
190
                    }
191 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

191
                    $metadata->/** @scrutinizer ignore-call */ 
192
                               setDiscriminatorMap($map);
Loading history...
192
                }
193
            }
194
        }
195
196
197
        // Evaluate <change-tracking-policy...>
198 37
        if (isset($xmlRoot['change-tracking-policy'])) {
199
            $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

199
            $metadata->/** @scrutinizer ignore-call */ 
200
                       setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_'
Loading history...
200
                . strtoupper((string) $xmlRoot['change-tracking-policy'])));
201
        }
202
203
        // Evaluate <indexes...>
204 37
        if (isset($xmlRoot->indexes)) {
205 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...
206 4
            foreach ($xmlRoot->indexes->index as $indexXml) {
207 4
                $index = ['columns' => explode(',', (string) $indexXml['columns'])];
208
209 4
                if (isset($indexXml['flags'])) {
210 1
                    $index['flags'] = explode(',', (string) $indexXml['flags']);
211
                }
212
213 4
                if (isset($indexXml->options)) {
214 1
                    $index['options'] = $this->_parseOptions($indexXml->options->children());
215
                }
216
217 4
                if (isset($indexXml['name'])) {
218 3
                    $metadata->table['indexes'][(string) $indexXml['name']] = $index;
219
                } else {
220 4
                    $metadata->table['indexes'][] = $index;
221
                }
222
            }
223
        }
224
225
        // Evaluate <unique-constraints..>
226 37
        if (isset($xmlRoot->{'unique-constraints'})) {
227 3
            $metadata->table['uniqueConstraints'] = [];
228 3
            foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) {
229 3
                $unique = ['columns' => explode(',', (string) $uniqueXml['columns'])];
230
231 3
                if (isset($uniqueXml->options)) {
232 3
                    $unique['options'] = $this->_parseOptions($uniqueXml->options->children());
233
                }
234
235 3
                if (isset($uniqueXml['name'])) {
236 3
                    $metadata->table['uniqueConstraints'][(string) $uniqueXml['name']] = $unique;
237
                } else {
238 3
                    $metadata->table['uniqueConstraints'][] = $unique;
239
                }
240
            }
241
        }
242
243 37
        if (isset($xmlRoot->options)) {
244 5
            $metadata->table['options'] = $this->_parseOptions($xmlRoot->options->children());
245
        }
246
247
        // The mapping assignment is done in 2 times as a bug might occurs on some php/xml lib versions
248
        // The internal SimpleXmlIterator get resetted, to this generate a duplicate field exception
249 37
        $mappings = [];
250
        // Evaluate <field ...> mappings
251 37
        if (isset($xmlRoot->field)) {
252 24
            foreach ($xmlRoot->field as $fieldMapping) {
253 24
                $mapping = $this->columnToArray($fieldMapping);
254
255 24
                if (isset($mapping['version'])) {
256 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

256
                    $metadata->/** @scrutinizer ignore-call */ 
257
                               setVersionMapping($mapping);
Loading history...
257 3
                    unset($mapping['version']);
258
                }
259
260 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

260
                $metadata->/** @scrutinizer ignore-call */ 
261
                           mapField($mapping);
Loading history...
261
            }
262
        }
263
264 37
        if (isset($xmlRoot->embedded)) {
265 3
            foreach ($xmlRoot->embedded as $embeddedMapping) {
266 3
                $columnPrefix = isset($embeddedMapping['column-prefix'])
267 3
                    ? (string) $embeddedMapping['column-prefix']
268 3
                    : null;
269
270 3
                $useColumnPrefix = isset($embeddedMapping['use-column-prefix'])
271 2
                    ? $this->evaluateBoolean($embeddedMapping['use-column-prefix'])
272 3
                    : true;
273
274
                $mapping = [
275 3
                    'fieldName' => (string) $embeddedMapping['name'],
276 3
                    'class' => (string) $embeddedMapping['class'],
277 3
                    'columnPrefix' => $useColumnPrefix ? $columnPrefix : false
278
                ];
279
280 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

280
                $metadata->/** @scrutinizer ignore-call */ 
281
                           mapEmbedded($mapping);
Loading history...
281
            }
282
        }
283
284 37
        foreach ($mappings as $mapping) {
285
            if (isset($mapping['version'])) {
286
                $metadata->setVersionMapping($mapping);
287
            }
288
289
            $metadata->mapField($mapping);
290
        }
291
292
        // Evaluate <id ...> mappings
293 37
        $associationIds = [];
294 37
        foreach ($xmlRoot->id as $idElement) {
295 34
            if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) {
296 2
                $associationIds[(string) $idElement['name']] = true;
297 2
                continue;
298
            }
299
300
            $mapping = [
301 33
                'id' => true,
302 33
                'fieldName' => (string) $idElement['name']
303
            ];
304
305 33
            if (isset($idElement['type'])) {
306 21
                $mapping['type'] = (string) $idElement['type'];
307
            }
308
309 33
            if (isset($idElement['length'])) {
310 3
                $mapping['length'] = (string) $idElement['length'];
311
            }
312
313 33
            if (isset($idElement['column'])) {
314 24
                $mapping['columnName'] = (string) $idElement['column'];
315
            }
316
317 33
            if (isset($idElement['column-definition'])) {
318 1
                $mapping['columnDefinition'] = (string) $idElement['column-definition'];
319
            }
320
321 33
            if (isset($idElement->options)) {
322 3
                $mapping['options'] = $this->_parseOptions($idElement->options->children());
323
            }
324
325 33
            $metadata->mapField($mapping);
326
327 33
            if (isset($idElement->generator)) {
328 32
                $strategy = isset($idElement->generator['strategy']) ?
329 32
                        (string) $idElement->generator['strategy'] : 'AUTO';
330 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

330
                $metadata->/** @scrutinizer ignore-call */ 
331
                           setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
Loading history...
331 32
                    . $strategy));
332
            }
333
334
            // Check for SequenceGenerator/TableGenerator definition
335 33
            if (isset($idElement->{'sequence-generator'})) {
336 3
                $seqGenerator = $idElement->{'sequence-generator'};
337 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

337
                $metadata->/** @scrutinizer ignore-call */ 
338
                           setSequenceGeneratorDefinition(
Loading history...
338
                    [
339 3
                        'sequenceName' => (string) $seqGenerator['sequence-name'],
340 3
                        'allocationSize' => (string) $seqGenerator['allocation-size'],
341 3
                        'initialValue' => (string) $seqGenerator['initial-value']
342
                    ]
343
                );
344 30
            } else if (isset($idElement->{'custom-id-generator'})) {
345 2
                $customGenerator = $idElement->{'custom-id-generator'};
346 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

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

401
                    /** @scrutinizer ignore-call */ 
402
                    $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...
402
                }
403
404 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

404
                $metadata->/** @scrutinizer ignore-call */ 
405
                           mapOneToOne($mapping);
Loading history...
405
            }
406
        }
407
408
        // Evaluate <one-to-many ...> mappings
409 37
        if (isset($xmlRoot->{'one-to-many'})) {
410 8
            foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) {
411
                $mapping = [
412 8
                    'fieldName' => (string) $oneToManyElement['field'],
413 8
                    'targetEntity' => (string) $oneToManyElement['target-entity'],
414 8
                    'mappedBy' => (string) $oneToManyElement['mapped-by']
415
                ];
416
417 8
                if (isset($oneToManyElement['fetch'])) {
418 2
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']);
419
                }
420
421 8
                if (isset($oneToManyElement->cascade)) {
422 6
                    $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
423
                }
424
425 8
                if (isset($oneToManyElement['orphan-removal'])) {
426 6
                    $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToManyElement['orphan-removal']);
427
                }
428
429 8
                if (isset($oneToManyElement->{'order-by'})) {
430 6
                    $orderBy = [];
431 6
                    foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
432 6
                        $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
433
                    }
434 6
                    $mapping['orderBy'] = $orderBy;
435
                }
436
437 8
                if (isset($oneToManyElement['index-by'])) {
438 3
                    $mapping['indexBy'] = (string) $oneToManyElement['index-by'];
439 5
                } else if (isset($oneToManyElement->{'index-by'})) {
440
                    throw new \InvalidArgumentException("<index-by /> is not a valid tag");
441
                }
442
443
                // Evaluate second level cache
444 8
                if (isset($oneToManyElement->cache)) {
445 1
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($oneToManyElement->cache));
446
                }
447
448 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

448
                $metadata->/** @scrutinizer ignore-call */ 
449
                           mapOneToMany($mapping);
Loading history...
449
            }
450
        }
451
452
        // Evaluate <many-to-one ...> mappings
453 37
        if (isset($xmlRoot->{'many-to-one'})) {
454 8
            foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) {
455
                $mapping = [
456 8
                    'fieldName' => (string) $manyToOneElement['field'],
457 8
                    'targetEntity' => (string) $manyToOneElement['target-entity']
458
                ];
459
460 8
                if (isset($associationIds[$mapping['fieldName']])) {
461 2
                    $mapping['id'] = true;
462
                }
463
464 8
                if (isset($manyToOneElement['fetch'])) {
465 1
                    $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $manyToOneElement['fetch']);
466
                }
467
468 8
                if (isset($manyToOneElement['inversed-by'])) {
469 1
                    $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by'];
470
                }
471
472 8
                $joinColumns = [];
473
474 8
                if (isset($manyToOneElement->{'join-column'})) {
475 5
                    $joinColumns[] = $this->joinColumnToArray($manyToOneElement->{'join-column'});
476 3
                } else if (isset($manyToOneElement->{'join-columns'})) {
477 2
                    foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
478 2
                        $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
479
                    }
480
                }
481
482 8
                $mapping['joinColumns'] = $joinColumns;
483
484 8
                if (isset($manyToOneElement->cascade)) {
485 2
                    $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
486
                }
487
488
                // Evaluate second level cache
489 8
                if (isset($manyToOneElement->cache)) {
490 1
                    $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], $this->cacheToArray($manyToOneElement->cache));
491
                }
492
493 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

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

564
                $metadata->/** @scrutinizer ignore-call */ 
565
                           mapManyToMany($mapping);
Loading history...
565
            }
566
        }
567
568
        // Evaluate association-overrides
569 36
        if (isset($xmlRoot->{'attribute-overrides'})) {
570 2
            foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) {
571 2
                $fieldName = (string) $overrideElement['name'];
572 2
                foreach ($overrideElement->field as $field) {
573 2
                    $mapping = $this->columnToArray($field);
574 2
                    $mapping['fieldName'] = $fieldName;
575 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

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

630
                $metadata->/** @scrutinizer ignore-call */ 
631
                           setAssociationOverride($fieldName, $override);
Loading history...
631
            }
632
        }
633
634
        // Evaluate <lifecycle-callbacks...>
635 36
        if (isset($xmlRoot->{'lifecycle-callbacks'})) {
636 5
            foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
637 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

637
                $metadata->/** @scrutinizer ignore-call */ 
638
                           addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string) $lifecycleCallback['type']));
Loading history...
638
            }
639
        }
640
641
        // Evaluate entity listener
642 36
        if (isset($xmlRoot->{'entity-listeners'})) {
643 6
            foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) {
644 6
                $className = (string) $listenerElement['class'];
645
                // Evaluate the listener using naming convention.
646 6
                if ($listenerElement->count() === 0) {
647 2
                    EntityListenerBuilder::bindEntityListener($metadata, $className);
648
649 2
                    continue;
650
                }
651
652 4
                foreach ($listenerElement as $callbackElement) {
653 4
                    $eventName   = (string) $callbackElement['type'];
654 4
                    $methodName  = (string) $callbackElement['method'];
655
656 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

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