Failed Conditions
Pull Request — master (#6959)
by Matthew
10:48
created

ClassMetadataFactory   F

Complexity

Total Complexity 108

Size/Duplication

Total Lines 597
Duplicated Lines 0 %

Test Coverage

Coverage 86.31%

Importance

Changes 0
Metric Value
dl 0
loc 597
ccs 227
cts 263
cp 0.8631
rs 1.5789
c 0
b 0
f 0
wmc 108

22 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A setEntityManager() 0 3 1
A loadMetadata() 0 7 1
A onNotFoundMetadata() 0 13 2
A getShortName() 0 9 2
B addInheritedSqlResultSetMappings() 0 22 4
A addInheritedNamedQueries() 0 8 3
B addDefaultDiscriminatorMap() 0 24 5
C completeFieldIdentifierGeneratorMapping() 0 70 14
D doLoadMetadata() 0 75 15
A addInheritedNamedNativeQueries() 0 13 3
B addInheritedProperties() 0 10 5
A completeIdentifierGeneratorMappings() 0 8 3
C validateRuntimeMetadata() 0 25 11
D resolveDiscriminatorValue() 0 26 10
C completeRuntimeMetadata() 0 28 8
A newClassMetadataBuildingContext() 0 6 1
A isEntity() 0 3 2
C buildValueGenerationPlan() 0 34 7
A getTargetPlatform() 0 7 2
A getDriver() 0 3 1
C createPropertyValueGenerator() 0 37 7

How to fix   Complexity   

Complex Class

Complex classes like ClassMetadataFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ClassMetadataFactory, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping;
6
7
use Doctrine\DBAL\Platforms;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
10
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
11
use Doctrine\ORM\Events;
12
use Doctrine\ORM\ORMException;
13
use Doctrine\ORM\Sequencing;
14
use Doctrine\ORM\Sequencing\Planning\ColumnValueGeneratorExecutor;
15
use Doctrine\ORM\Sequencing\Planning\CompositeValueGenerationPlan;
16
use Doctrine\ORM\Sequencing\Planning\NoopValueGenerationPlan;
17
use Doctrine\ORM\Sequencing\Planning\SingleValueGenerationPlan;
18
use ReflectionException;
19
20
/**
21
 * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
22
 * metadata mapping information of a class which describes how a class should be mapped
23
 * to a relational database.
24
 */
25
class ClassMetadataFactory extends AbstractClassMetadataFactory
26
{
27
    /**
28
     * @var EntityManagerInterface|null
29
     */
30
    private $em;
31
32
    /**
33
     * @var \Doctrine\DBAL\Platforms\AbstractPlatform
34
     */
35
    private $targetPlatform;
36
37
    /**
38
     * @var Driver\MappingDriver
39
     */
40
    private $driver;
41
42
    /**
43
     * @var \Doctrine\Common\EventManager
44
     */
45
    private $evm;
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 374
    protected function loadMetadata(string $name, ClassMetadataBuildingContext $metadataBuildingContext) : array
51
    {
52 374
        $loaded = parent::loadMetadata($name, $metadataBuildingContext);
53
54 355
        array_map([$this, 'resolveDiscriminatorValue'], $loaded);
55
56 355
        return $loaded;
57
    }
58
59 2255
    public function setEntityManager(EntityManagerInterface $em)
60
    {
61 2255
        $this->em = $em;
62 2255
    }
63
64
    /**
65
     * {@inheritdoc}
66
     *
67
     * @throws ORMException
68
     */
69 440
    protected function initialize() : void
70
    {
71 440
        $this->driver      = $this->em->getConfiguration()->getMetadataDriverImpl();
72 440
        $this->evm         = $this->em->getEventManager();
73 440
        $this->initialized = true;
74 440
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 12
    protected function onNotFoundMetadata(
80
        string $className,
81
        ClassMetadataBuildingContext $metadataBuildingContext
82
    ) : ?ClassMetadata {
83 12
        if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
84 10
            return null;
85
        }
86
87 2
        $eventArgs = new OnClassMetadataNotFoundEventArgs($className, $metadataBuildingContext, $this->em);
88
89 2
        $this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
90
91 2
        return $eventArgs->getFoundMetadata();
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     *
97
     * @throws MappingException
98
     * @throws ORMException
99
     */
100 362
    protected function doLoadMetadata(
101
        string $className,
102
        ?ClassMetadata $parent,
103
        ClassMetadataBuildingContext $metadataBuildingContext
104
    ) : ClassMetadata {
105 362
        $classMetadata = new ClassMetadata($className, $metadataBuildingContext);
106
107 362
        if ($parent) {
108 99
            $classMetadata->setParent($parent);
109
110 99
            $this->addInheritedProperties($classMetadata, $parent);
111
112 98
            $classMetadata->setInheritanceType($parent->inheritanceType);
113 98
            $classMetadata->setIdentifier($parent->identifier);
114
115 98
            if ($parent->discriminatorColumn) {
116 72
                $classMetadata->setDiscriminatorColumn($parent->discriminatorColumn);
117 72
                $classMetadata->setDiscriminatorMap($parent->discriminatorMap);
118
            }
119
120 98
            $classMetadata->setLifecycleCallbacks($parent->lifecycleCallbacks);
121 98
            $classMetadata->setChangeTrackingPolicy($parent->changeTrackingPolicy);
122
123 98
            if ($parent->isMappedSuperclass) {
124 28
                $classMetadata->setCustomRepositoryClassName($parent->getCustomRepositoryClassName());
125
            }
126
        }
127
128
        // Invoke driver
129
        try {
130 362
            $this->driver->loadMetadataForClass($classMetadata->getClassName(), $classMetadata, $metadataBuildingContext);
131 2
        } catch (ReflectionException $e) {
132
            throw MappingException::reflectionFailure($classMetadata->getClassName(), $e);
133
        }
134
135 360
        $this->completeIdentifierGeneratorMappings($classMetadata);
136
137 360
        if ($parent) {
138 98
            $this->addInheritedNamedQueries($classMetadata, $parent);
139
140 98
            $parentCache = $parent->getCache();
141
            
142 98
            if ($parentCache) {
143 3
                $classMetadata->setCache(clone $parentCache);
144
            }
145
146 98
            if (! empty($parent->namedNativeQueries)) {
147 7
                $this->addInheritedNamedNativeQueries($classMetadata, $parent);
148
            }
149
150 98
            if (! empty($parent->sqlResultSetMappings)) {
151 7
                $this->addInheritedSqlResultSetMappings($classMetadata, $parent);
152
            }
153
154 98
            if (! empty($parent->entityListeners) && empty($classMetadata->entityListeners)) {
155 7
                $classMetadata->entityListeners = $parent->entityListeners;
156
            }
157
        }
158
159 360
        if (! $classMetadata->discriminatorMap && $classMetadata->inheritanceType !== InheritanceType::NONE && $classMetadata->isRootEntity()) {
160 1
            $this->addDefaultDiscriminatorMap($classMetadata);
161
        }
162
163 360
        $this->completeRuntimeMetadata($classMetadata, $parent);
164
165 360
        if ($this->evm->hasListeners(Events::loadClassMetadata)) {
166 6
            $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->em);
167
168 6
            $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
169
        }
170
171 359
        $this->buildValueGenerationPlan($classMetadata);
172 359
        $this->validateRuntimeMetadata($classMetadata, $parent);
173
174 357
        return $classMetadata;
175
    }
176
177 360
    protected function completeRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
178
    {
179 360
        if (! $parent || ! $parent->isMappedSuperclass) {
180 360
            return;
181
        }
182
183 28
        if ($class->isMappedSuperclass) {
184 1
            return;
185
        }
186
187 28
        $tableName = $class->getTableName();
188
189
        // Resolve column table names
190 28
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
191 28
            if ($property instanceof FieldMetadata) {
192 28
                $property->setTableName($property->getTableName() ?? $tableName);
193
194 28
                continue;
195
            }
196
197 12
            if (! ($property instanceof ToOneAssociationMetadata)) {
198 12
                continue;
199
            }
200
201
            // Resolve association join column table names
202 9
            foreach ($property->getJoinColumns() as $joinColumn) {
203
                /** @var JoinColumnMetadata $joinColumn */
204 9
                $joinColumn->setTableName($joinColumn->getTableName() ?? $tableName);
205
            }
206
        }
207 28
    }
208
209
    /**
210
     * Validate runtime metadata is correctly defined.
211
     *
212
     * @throws MappingException
213
     */
214 359
    protected function validateRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
215
    {
216 359
        if (! $class->getReflectionClass()) {
217
            // only validate if there is a reflection class instance
218
            return;
219
        }
220
221 359
        $class->validateIdentifier();
222 357
        $class->validateAssociations();
223 357
        $class->validateLifecycleCallbacks($this->getReflectionService());
224
225
        // verify inheritance
226 357
        if (! $class->isMappedSuperclass && $class->inheritanceType !== InheritanceType::NONE) {
227 75
            if (! $parent) {
228 73
                if (! $class->discriminatorMap) {
229
                    throw MappingException::missingDiscriminatorMap($class->getClassName());
230
                }
231
232 73
                if (! $class->discriminatorColumn) {
233 75
                    throw MappingException::missingDiscriminatorColumn($class->getClassName());
234
                }
235
            }
236 321
        } elseif (($class->discriminatorMap || $class->discriminatorColumn) && $class->isMappedSuperclass && $class->isRootEntity()) {
237
            // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
238
            throw MappingException::noInheritanceOnMappedSuperClass($class->getClassName());
239
        }
240 357
    }
241
242
    /**
243
     * {@inheritdoc}
244
     */
245 1953
    protected function newClassMetadataBuildingContext() : ClassMetadataBuildingContext
246
    {
247 1953
        return new ClassMetadataBuildingContext(
248 1953
            $this,
249 1953
            $this->getReflectionService(),
250 1953
            $this->em->getConfiguration()->getNamingStrategy()
251
        );
252
    }
253
254
    /**
255
     * Populates the discriminator value of the given metadata (if not set) by iterating over discriminator
256
     * map classes and looking for a fitting one.
257
     *
258
     * @throws \InvalidArgumentException
259
     * @throws \ReflectionException
260
     * @throws MappingException
261
     */
262 355
    private function resolveDiscriminatorValue(ClassMetadata $metadata) : void
263
    {
264 355
        if ($metadata->discriminatorValue || ! $metadata->discriminatorMap || $metadata->isMappedSuperclass ||
265 355
            ! $metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
266 355
            return;
267
        }
268
269
        // minor optimization: avoid loading related metadata when not needed
270 4
        foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
271 4
            if ($discriminatorClass === $metadata->getClassName()) {
272 3
                $metadata->discriminatorValue = $discriminatorValue;
273
274 4
                return;
275
            }
276
        }
277
278
        // iterate over discriminator mappings and resolve actual referenced classes according to existing metadata
279 1
        foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
280 1
            if ($metadata->getClassName() === $this->getMetadataFor($discriminatorClass)->getClassName()) {
281
                $metadata->discriminatorValue = $discriminatorValue;
282
283 1
                return;
284
            }
285
        }
286
287 1
        throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->getClassName(), $metadata->getRootClassName());
288
    }
289
290
    /**
291
     * Adds a default discriminator map if no one is given
292
     *
293
     * If an entity is of any inheritance type and does not contain a
294
     * discriminator map, then the map is generated automatically. This process
295
     * is expensive computation wise.
296
     *
297
     * The automatically generated discriminator map contains the lowercase short name of
298
     * each class as key.
299
     *
300
     * @throws MappingException
301
     */
302 1
    private function addDefaultDiscriminatorMap(ClassMetadata $class) : void
303
    {
304 1
        $allClasses = $this->driver->getAllClassNames();
305 1
        $fqcn       = $class->getClassName();
306 1
        $map        = [$this->getShortName($fqcn) => $fqcn];
307 1
        $duplicates = [];
308
309 1
        foreach ($allClasses as $subClassCandidate) {
310 1
            if (is_subclass_of($subClassCandidate, $fqcn)) {
311 1
                $shortName = $this->getShortName($subClassCandidate);
312
313 1
                if (isset($map[$shortName])) {
314
                    $duplicates[] = $shortName;
315
                }
316
317 1
                $map[$shortName] = $subClassCandidate;
318
            }
319
        }
320
321 1
        if ($duplicates) {
322
            throw MappingException::duplicateDiscriminatorEntry($class->getClassName(), $duplicates, $map);
323
        }
324
325 1
        $class->setDiscriminatorMap($map);
326 1
    }
327
328
    /**
329
     * Gets the lower-case short name of a class.
330
     *
331
     * @param string $className
332
     */
333 1
    private function getShortName($className) : string
334
    {
335 1
        if (strpos($className, '\\') === false) {
336
            return strtolower($className);
337
        }
338
339 1
        $parts = explode('\\', $className);
340
341 1
        return strtolower(end($parts));
342
    }
343
344
    /**
345
     * Adds inherited fields to the subclass mapping.
346
     *
347
     * @throws MappingException
348
     */
349 99
    private function addInheritedProperties(ClassMetadata $subClass, ClassMetadata $parentClass) : void
350
    {
351 99
        $isAbstract = $parentClass->isMappedSuperclass;
352
353 99
        foreach ($parentClass->getDeclaredPropertiesIterator() as $fieldName => $property) {
354 98
            if ($isAbstract && $property instanceof ToManyAssociationMetadata && ! $property->isOwningSide()) {
355 1
                throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->getClassName(), $fieldName);
356
            }
357
358 97
            $subClass->addInheritedProperty($property);
359
        }
360 98
    }
361
362
    /**
363
     * Adds inherited named queries to the subclass mapping.
364
     *
365
     * @throws MappingException
366
     */
367 98
    private function addInheritedNamedQueries(ClassMetadata $subClass, ClassMetadata $parentClass) : void
368
    {
369 98
        foreach ($parentClass->getNamedQueries() as $name => $query) {
370 1
            if ($subClass->hasNamedQuery($name)) {
371 1
                continue;
372
            }
373
374 1
            $subClass->addNamedQuery($name, $query);
375
        }
376 98
    }
377
378
    /**
379
     * Adds inherited named native queries to the subclass mapping.
380
     *
381
     * @throws MappingException
382
     */
383 7
    private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMetadata $parentClass) : void
384
    {
385 7
        foreach ($parentClass->namedNativeQueries as $name => $query) {
386 7
            if (isset($subClass->namedNativeQueries[$name])) {
387 4
                continue;
388
            }
389
390 7
            $subClass->addNamedNativeQuery(
391 7
                $name,
392 7
                $query['query'],
393
                [
394 7
                    'resultSetMapping' => $query['resultSetMapping'],
395 7
                    'resultClass'      => $query['resultClass'],
396
                ]
397
            );
398
        }
399 7
    }
400
401
    /**
402
     * Adds inherited sql result set mappings to the subclass mapping.
403
     *
404
     * @throws MappingException
405
     */
406 7
    private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, ClassMetadata $parentClass) : void
407
    {
408 7
        foreach ($parentClass->sqlResultSetMappings as $name => $mapping) {
409 7
            if (isset($subClass->sqlResultSetMappings[$name])) {
410 4
                continue;
411
            }
412
413 7
            $entities = [];
414
415 7
            foreach ($mapping['entities'] as $entity) {
416 7
                $entities[] = [
417 7
                    'fields'              => $entity['fields'],
418 7
                    'discriminatorColumn' => $entity['discriminatorColumn'],
419 7
                    'entityClass'         => $entity['entityClass'],
420
                ];
421
            }
422
423 7
            $subClass->addSqlResultSetMapping(
424
                [
425 7
                    'name'     => $mapping['name'],
426 7
                    'columns'  => $mapping['columns'],
427 7
                    'entities' => $entities,
428
                ]
429
            );
430
        }
431 7
    }
432
433
    /**
434
     * Completes the ID generator mapping. If "auto" is specified we choose the generator
435
     * most appropriate for the targeted database platform.
436
     *
437
     * @throws ORMException
438
     */
439 360
    private function completeIdentifierGeneratorMappings(ClassMetadata $class) : void
440
    {
441 360
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
442 358
            if (! $property instanceof FieldMetadata /*&& ! $property instanceof AssocationMetadata*/) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
443 248
                continue;
444
            }
445
446 355
            $this->completeFieldIdentifierGeneratorMapping($property);
447
        }
448 360
    }
449
450 355
    private function completeFieldIdentifierGeneratorMapping(FieldMetadata $field)
451
    {
452 355
        if (! $field->hasValueGenerator()) {
453 275
            return;
454
        }
455
456 286
        $platform  = $this->getTargetPlatform();
457 286
        $class     = $field->getDeclaringClass();
458 286
        $generator = $field->getValueGenerator();
459
460 286
        if ($generator->getType() === GeneratorType::AUTO) {
461 275
            $generator = new ValueGeneratorMetadata(
462 275
                $platform->prefersSequences()
463
                    ? GeneratorType::SEQUENCE
464 275
                    : ($platform->prefersIdentityColumns()
465 275
                        ? GeneratorType::IDENTITY
466 275
                        : GeneratorType::TABLE
467
                ),
468 275
                $field->getValueGenerator()->getDefinition()
469
            );
470 275
            $field->setValueGenerator($generator);
471
        }
472
473
        // Validate generator definition and set defaults where needed
474 286
        switch ($generator->getType()) {
475 286
            case GeneratorType::SEQUENCE:
476
                // If there is no sequence definition yet, create a default definition
477 6
                if ($generator->getDefinition()) {
478 6
                    break;
479
                }
480
481
                // @todo guilhermeblanco Move sequence generation to DBAL
482
                $sequencePrefix = $platform->getSequencePrefix($field->getTableName(), $field->getSchemaName());
483
                $idSequenceName = sprintf('%s_%s_seq', $sequencePrefix, $field->getColumnName());
484
                $sequenceName   = $platform->fixSchemaElementName($idSequenceName);
485
486
                $field->setValueGenerator(
487
                    new ValueGeneratorMetadata(
488
                        $generator->getType(),
489
                        [
490
                            'sequenceName'   => $sequenceName,
491
                            'allocationSize' => 1,
492
                        ]
493
                    )
494
                );
495
496
                break;
497
498 280
            case GeneratorType::TABLE:
499
                throw new ORMException('TableGenerator not yet implemented.');
500
                break;
501
502 280
            case GeneratorType::CUSTOM:
503 1
                $definition = $generator->getDefinition();
504 1
                if (! isset($definition['class'])) {
505
                    throw new ORMException(sprintf('Cannot instantiate custom generator, no class has been defined'));
506
                }
507 1
                if (! class_exists($definition['class'])) {
508
                    throw new ORMException(sprintf('Cannot instantiate custom generator : %s', var_export($definition, true))); //$definition['class']));
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
509
                }
510
511 1
                break;
512
513 279
            case GeneratorType::IDENTITY:
514
            case GeneratorType::NONE:
515
            case GeneratorType::UUID:
516 279
                break;
517
518
            default:
519
                throw new ORMException('Unknown generator type: ' . $generator->getType());
520
        }
521 286
    }
522
523
    /**
524
     * {@inheritDoc}
525
     */
526 197
    protected function getDriver() : Driver\MappingDriver
527
    {
528 197
        return $this->driver;
529
    }
530
531
    /**
532
     * {@inheritDoc}
533
     */
534
    protected function isEntity(ClassMetadata $class) : bool
535
    {
536
        return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
537
    }
538
539 286
    private function getTargetPlatform() : Platforms\AbstractPlatform
540
    {
541 286
        if (! $this->targetPlatform) {
542 286
            $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
543
        }
544
545 286
        return $this->targetPlatform;
546
    }
547
548 359
    private function buildValueGenerationPlan(ClassMetadata $class) : void
549
    {
550
        /** @var LocalColumnMetadata[] $generatedProperties */
551 359
        $generatedProperties = [];
552
553 359
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
554 357
            if (! ($property instanceof LocalColumnMetadata && $property->hasValueGenerator())) {
555 327
                continue;
556
            }
557
558 285
            $generatedProperties[] = $property;
559
        }
560
561 359
        switch (count($generatedProperties)) {
562 359
            case 0:
563 113
                $class->setValueGenerationPlan(new NoopValueGenerationPlan());
564 113
                break;
565
566 285
            case 1:
567 285
                $property = reset($generatedProperties);
568 285
                $executor = new ColumnValueGeneratorExecutor($property, $this->createPropertyValueGenerator($class, $property));
569
570 285
                $class->setValueGenerationPlan(new SingleValueGenerationPlan($class, $executor));
571 285
                break;
572
573
            default:
574
                $executors = [];
575
576
                foreach ($generatedProperties as $property) {
577
                    $executors[] = new ColumnValueGeneratorExecutor($property, $this->createPropertyValueGenerator($class, $property));
578
                }
579
580
                $class->setValueGenerationPlan(new CompositeValueGenerationPlan($class, $executors));
581
                break;
582
        }
583 359
    }
584
585 285
    private function createPropertyValueGenerator(
586
        ClassMetadata $class,
587
        LocalColumnMetadata $property
588
    ) : Sequencing\Generator {
589 285
        $platform = $this->getTargetPlatform();
590
591 285
        switch ($property->getValueGenerator()->getType()) {
592 285
            case GeneratorType::IDENTITY:
593 278
                $sequenceName = null;
594
595
                // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
596 278
                if ($platform->usesSequenceEmulatedIdentityColumns()) {
597
                    $sequencePrefix = $platform->getSequencePrefix($class->getTableName(), $class->getSchemaName());
598
                    $idSequenceName = $platform->getIdentitySequenceName($sequencePrefix, $property->getColumnName());
599
                    $sequenceName   = $platform->quoteIdentifier($platform->fixSchemaElementName($idSequenceName));
600
                }
601
602 278
                return $property->getTypeName() === 'bigint'
603 1
                    ? new Sequencing\BigIntegerIdentityGenerator($sequenceName)
604 278
                    : new Sequencing\IdentityGenerator($sequenceName);
605
606 7
            case GeneratorType::SEQUENCE:
607 6
                $definition = $property->getValueGenerator()->getDefinition();
608 6
                return new Sequencing\SequenceGenerator(
609 6
                    $platform->quoteIdentifier($definition['sequenceName']),
610 6
                    $definition['allocationSize']
611
                );
612
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
613
614 1
            case GeneratorType::UUID:
615
                return new Sequencing\UuidGenerator();
616
                break;
617
618 1
            case GeneratorType::CUSTOM:
619 1
                $class = $property->getValueGenerator()->getDefinition()['class'];
620 1
                return new $class();
621
                break;
622
        }
623
    }
624
}
625