Failed Conditions
Pull Request — master (#7297)
by Gabriel
11:55
created

ClassMetadataFactory::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping;
6
7
use Doctrine\Common\EventManager;
8
use Doctrine\DBAL\Platforms;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\ORM\EntityManagerInterface;
11
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
12
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
13
use Doctrine\ORM\Events;
14
use Doctrine\ORM\Exception\ORMException;
15
use Doctrine\ORM\Mapping\Exception\InvalidCustomGenerator;
16
use Doctrine\ORM\Mapping\Exception\TableGeneratorNotImplementedYet;
17
use Doctrine\ORM\Mapping\Exception\UnknownGeneratorType;
18
use Doctrine\ORM\Sequencing;
19
use Doctrine\ORM\Sequencing\Planning\AssociationValueGeneratorExecutor;
20
use Doctrine\ORM\Sequencing\Planning\ColumnValueGeneratorExecutor;
21
use Doctrine\ORM\Sequencing\Planning\CompositeValueGenerationPlan;
22
use Doctrine\ORM\Sequencing\Planning\NoopValueGenerationPlan;
23
use Doctrine\ORM\Sequencing\Planning\SingleValueGenerationPlan;
24
use Doctrine\ORM\Sequencing\Planning\ValueGenerationExecutor;
25
use ReflectionException;
26
use function array_map;
27
use function class_exists;
28
use function count;
29
use function end;
30
use function explode;
31
use function is_subclass_of;
32
use function sprintf;
33
use function strpos;
34
use function strtolower;
35
36
/**
37
 * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
38
 * metadata mapping information of a class which describes how a class should be mapped
39
 * to a relational database.
40
 */
41
class ClassMetadataFactory extends AbstractClassMetadataFactory
42
{
43
    /** @var EntityManagerInterface|null */
44
    private $em;
45
46
    /** @var AbstractPlatform */
47
    private $targetPlatform;
48
49
    /** @var Driver\MappingDriver */
50
    private $driver;
51
52
    /** @var EventManager */
53
    private $evm;
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 380
    protected function loadMetadata(string $name, ClassMetadataBuildingContext $metadataBuildingContext) : array
59
    {
60 380
        $loaded = parent::loadMetadata($name, $metadataBuildingContext);
61
62 361
        array_map([$this, 'resolveDiscriminatorValue'], $loaded);
63
64 361
        return $loaded;
65
    }
66
67 2250
    public function setEntityManager(EntityManagerInterface $em)
68
    {
69 2250
        $this->em = $em;
70 2250
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 446
    protected function initialize() : void
76
    {
77 446
        $this->driver      = $this->em->getConfiguration()->getMetadataDriverImpl();
0 ignored issues
show
Bug introduced by
The method getConfiguration() does not exist on null. ( Ignorable by Annotation )

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

77
        $this->driver      = $this->em->/** @scrutinizer ignore-call */ getConfiguration()->getMetadataDriverImpl();

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...
78 446
        $this->evm         = $this->em->getEventManager();
79 446
        $this->initialized = true;
80 446
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 12
    protected function onNotFoundMetadata(
86
        string $className,
87
        ClassMetadataBuildingContext $metadataBuildingContext
88
    ) : ?ClassMetadata {
89 12
        if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
90 10
            return null;
91
        }
92
93 2
        $eventArgs = new OnClassMetadataNotFoundEventArgs($className, $metadataBuildingContext, $this->em);
0 ignored issues
show
Bug introduced by
It seems like $this->em can also be of type null; however, parameter $entityManager of Doctrine\ORM\Event\OnCla...ventArgs::__construct() does only seem to accept Doctrine\ORM\EntityManagerInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

93
        $eventArgs = new OnClassMetadataNotFoundEventArgs($className, $metadataBuildingContext, /** @scrutinizer ignore-type */ $this->em);
Loading history...
94
95 2
        $this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
96
97 2
        return $eventArgs->getFoundMetadata();
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     *
103
     * @throws MappingException
104
     * @throws ORMException
105
     */
106 368
    protected function doLoadMetadata(
107
        string $className,
108
        ?ClassMetadata $parent,
109
        ClassMetadataBuildingContext $metadataBuildingContext
110
    ) : ClassMetadata {
111 368
        $classMetadata = new ClassMetadata($className, $metadataBuildingContext);
112
113 368
        if ($parent) {
114 98
            $classMetadata->setParent($parent);
115
116 98
            foreach ($parent->getDeclaredPropertiesIterator() as $fieldName => $property) {
117 97
                $classMetadata->addInheritedProperty($property);
118
            }
119
120 98
            $classMetadata->setInheritanceType($parent->inheritanceType);
0 ignored issues
show
Bug introduced by
$parent->inheritanceType of type string is incompatible with the type integer expected by parameter $type of Doctrine\ORM\Mapping\Cla...a::setInheritanceType(). ( Ignorable by Annotation )

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

120
            $classMetadata->setInheritanceType(/** @scrutinizer ignore-type */ $parent->inheritanceType);
Loading history...
121 98
            $classMetadata->setIdentifier($parent->identifier);
122
123 98
            if ($parent->discriminatorColumn) {
124 72
                $classMetadata->setDiscriminatorColumn($parent->discriminatorColumn);
125 72
                $classMetadata->setDiscriminatorMap($parent->discriminatorMap);
126
            }
127
128 98
            $classMetadata->setLifecycleCallbacks($parent->lifecycleCallbacks);
129 98
            $classMetadata->setChangeTrackingPolicy($parent->changeTrackingPolicy);
130
131 98
            if ($parent->isMappedSuperclass) {
132 28
                $classMetadata->setCustomRepositoryClassName($parent->getCustomRepositoryClassName());
133
            }
134
        }
135
136
        // Invoke driver
137
        try {
138 368
            $this->driver->loadMetadataForClass($classMetadata->getClassName(), $classMetadata, $metadataBuildingContext);
139 3
        } catch (ReflectionException $e) {
140
            throw MappingException::reflectionFailure($classMetadata->getClassName(), $e);
141
        }
142
143 365
        $this->completeIdentifierGeneratorMappings($classMetadata);
144
145 365
        if ($parent) {
146 98
            if ($parent->getCache()) {
147 3
                $classMetadata->setCache(clone $parent->getCache());
148
            }
149
150 98
            if (! empty($parent->entityListeners) && empty($classMetadata->entityListeners)) {
151 7
                $classMetadata->entityListeners = $parent->entityListeners;
152
            }
153
        }
154
155 365
        if (! $classMetadata->discriminatorMap && $classMetadata->inheritanceType !== InheritanceType::NONE && $classMetadata->isRootEntity()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $classMetadata->discriminatorMap of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
156 1
            $this->addDefaultDiscriminatorMap($classMetadata);
157
        }
158
159 365
        $this->completeRuntimeMetadata($classMetadata, $parent);
160
161 365
        if ($this->evm->hasListeners(Events::loadClassMetadata)) {
162 6
            $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->em);
0 ignored issues
show
Bug introduced by
It seems like $this->em can also be of type null; however, parameter $entityManager of Doctrine\ORM\Event\LoadC...ventArgs::__construct() does only seem to accept Doctrine\ORM\EntityManagerInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

162
            $eventArgs = new LoadClassMetadataEventArgs($classMetadata, /** @scrutinizer ignore-type */ $this->em);
Loading history...
163
164 6
            $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
165
        }
166
167 364
        $this->buildValueGenerationPlan($classMetadata);
168 364
        $this->validateRuntimeMetadata($classMetadata, $parent);
169
170 362
        return $classMetadata;
171
    }
172
173 365
    protected function completeRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
174
    {
175 365
        if (! $parent || ! $parent->isMappedSuperclass) {
176 365
            return;
177
        }
178
179 28
        if ($class->isMappedSuperclass) {
180 1
            return;
181
        }
182
183 28
        $tableName = $class->getTableName();
184
185
        // Resolve column table names
186 28
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
187 28
            if ($property instanceof FieldMetadata) {
188 28
                $property->setTableName($property->getTableName() ?? $tableName);
189
190 28
                continue;
191
            }
192
193 12
            if (! ($property instanceof ToOneAssociationMetadata)) {
194 12
                continue;
195
            }
196
197
            // Resolve association join column table names
198 9
            foreach ($property->getJoinColumns() as $joinColumn) {
199
                /** @var JoinColumnMetadata $joinColumn */
200 9
                $joinColumn->setTableName($joinColumn->getTableName() ?? $tableName);
201
            }
202
        }
203 28
    }
204
205
    /**
206
     * Validate runtime metadata is correctly defined.
207
     *
208
     * @throws MappingException
209
     */
210 364
    protected function validateRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
211
    {
212 364
        if (! $class->getReflectionClass()) {
213
            // only validate if there is a reflection class instance
214
            return;
215
        }
216
217 364
        $class->validateIdentifier();
218 362
        $class->validateAssociations();
219 362
        $class->validateLifecycleCallbacks($this->getReflectionService());
220
221
        // verify inheritance
222 362
        if (! $class->isMappedSuperclass && $class->inheritanceType !== InheritanceType::NONE) {
223 75
            if (! $parent) {
224 74
                if (! $class->discriminatorMap) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $class->discriminatorMap of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
225
                    throw MappingException::missingDiscriminatorMap($class->getClassName());
226
                }
227
228 74
                if (! $class->discriminatorColumn) {
229 75
                    throw MappingException::missingDiscriminatorColumn($class->getClassName());
230
                }
231
            }
232 326
        } elseif (($class->discriminatorMap || $class->discriminatorColumn) && $class->isMappedSuperclass && $class->isRootEntity()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $class->discriminatorMap of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
233
            // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
234
            throw MappingException::noInheritanceOnMappedSuperClass($class->getClassName());
235
        }
236 362
    }
237
238
    /**
239
     * {@inheritdoc}
240
     */
241 1952
    protected function newClassMetadataBuildingContext() : ClassMetadataBuildingContext
242
    {
243 1952
        return new ClassMetadataBuildingContext(
244 1952
            $this,
245 1952
            $this->getReflectionService(),
246 1952
            $this->em->getConfiguration()->getNamingStrategy()
247
        );
248
    }
249
250
    /**
251
     * Populates the discriminator value of the given metadata (if not set) by iterating over discriminator
252
     * map classes and looking for a fitting one.
253
     *
254
     * @throws \InvalidArgumentException
255
     * @throws \ReflectionException
256
     * @throws MappingException
257
     */
258 361
    private function resolveDiscriminatorValue(ClassMetadata $metadata) : void
259
    {
260 361
        if ($metadata->discriminatorValue || ! $metadata->discriminatorMap || $metadata->isMappedSuperclass ||
0 ignored issues
show
Bug Best Practice introduced by
The expression $metadata->discriminatorMap of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
261 361
            ! $metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
262 361
            return;
263
        }
264
265
        // minor optimization: avoid loading related metadata when not needed
266 4
        foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
267 4
            if ($discriminatorClass === $metadata->getClassName()) {
268 3
                $metadata->discriminatorValue = $discriminatorValue;
269
270 4
                return;
271
            }
272
        }
273
274
        // iterate over discriminator mappings and resolve actual referenced classes according to existing metadata
275 1
        foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
276 1
            if ($metadata->getClassName() === $this->getMetadataFor($discriminatorClass)->getClassName()) {
277
                $metadata->discriminatorValue = $discriminatorValue;
278
279 1
                return;
280
            }
281
        }
282
283 1
        throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->getClassName(), $metadata->getRootClassName());
284
    }
285
286
    /**
287
     * Adds a default discriminator map if no one is given
288
     *
289
     * If an entity is of any inheritance type and does not contain a
290
     * discriminator map, then the map is generated automatically. This process
291
     * is expensive computation wise.
292
     *
293
     * The automatically generated discriminator map contains the lowercase short name of
294
     * each class as key.
295
     *
296
     * @throws MappingException
297
     */
298 1
    private function addDefaultDiscriminatorMap(ClassMetadata $class) : void
299
    {
300 1
        $allClasses = $this->driver->getAllClassNames();
301 1
        $fqcn       = $class->getClassName();
302 1
        $map        = [$this->getShortName($fqcn) => $fqcn];
303 1
        $duplicates = [];
304
305 1
        foreach ($allClasses as $subClassCandidate) {
306 1
            if (is_subclass_of($subClassCandidate, $fqcn)) {
307 1
                $shortName = $this->getShortName($subClassCandidate);
308
309 1
                if (isset($map[$shortName])) {
310
                    $duplicates[] = $shortName;
311
                }
312
313 1
                $map[$shortName] = $subClassCandidate;
314
            }
315
        }
316
317 1
        if ($duplicates) {
318
            throw MappingException::duplicateDiscriminatorEntry($class->getClassName(), $duplicates, $map);
319
        }
320
321 1
        $class->setDiscriminatorMap($map);
322 1
    }
323
324
    /**
325
     * Gets the lower-case short name of a class.
326
     *
327
     * @param string $className
328
     */
329 1
    private function getShortName($className) : string
330
    {
331 1
        if (strpos($className, '\\') === false) {
332
            return strtolower($className);
333
        }
334
335 1
        $parts = explode('\\', $className);
336
337 1
        return strtolower(end($parts));
338
    }
339
340
    /**
341
     * Completes the ID generator mapping. If "auto" is specified we choose the generator
342
     * most appropriate for the targeted database platform.
343
     *
344
     * @throws ORMException
345
     */
346 365
    private function completeIdentifierGeneratorMappings(ClassMetadata $class) : void
347
    {
348 365
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
349 363
            if (! $property instanceof FieldMetadata /*&& ! $property instanceof AssocationMetadata*/) {
350 251
                continue;
351
            }
352
353 361
            $this->completeFieldIdentifierGeneratorMapping($property);
354
        }
355 365
    }
356
357 361
    private function completeFieldIdentifierGeneratorMapping(FieldMetadata $field)
358
    {
359 361
        if (! $field->hasValueGenerator()) {
360 280
            return;
361
        }
362
363 289
        $platform  = $this->getTargetPlatform();
364 289
        $generator = $field->getValueGenerator();
365
366 289
        if ($generator->getType() === GeneratorType::AUTO) {
367 279
            $generator = new ValueGeneratorMetadata(
368 279
                $platform->prefersSequences()
369
                    ? GeneratorType::SEQUENCE
370 279
                    : ($platform->prefersIdentityColumns()
371 279
                        ? GeneratorType::IDENTITY
372 279
                        : GeneratorType::TABLE
373
                ),
374 279
                $field->getValueGenerator()->getDefinition()
375
            );
376 279
            $field->setValueGenerator($generator);
377
        }
378
379
        // Validate generator definition and set defaults where needed
380 289
        switch ($generator->getType()) {
381 289
            case GeneratorType::SEQUENCE:
382
                // If there is no sequence definition yet, create a default definition
383 6
                if ($generator->getDefinition()) {
384 6
                    break;
385
                }
386
387
                // @todo guilhermeblanco Move sequence generation to DBAL
388
                $sequencePrefix = $platform->getSequencePrefix($field->getTableName(), $field->getSchemaName());
0 ignored issues
show
Bug introduced by
The method getSchemaName() does not exist on Doctrine\ORM\Mapping\FieldMetadata. ( Ignorable by Annotation )

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

388
                $sequencePrefix = $platform->getSequencePrefix($field->getTableName(), $field->/** @scrutinizer ignore-call */ getSchemaName());

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...
389
                $idSequenceName = sprintf('%s_%s_seq', $sequencePrefix, $field->getColumnName());
390
                $sequenceName   = $platform->fixSchemaElementName($idSequenceName);
391
392
                $field->setValueGenerator(
393
                    new ValueGeneratorMetadata(
394
                        $generator->getType(),
395
                        [
396
                            'sequenceName'   => $sequenceName,
397
                            'allocationSize' => 1,
398
                        ]
399
                    )
400
                );
401
402
                break;
403
404 283
            case GeneratorType::TABLE:
405
                throw TableGeneratorNotImplementedYet::create();
406
                break;
407
408 283
            case GeneratorType::CUSTOM:
409 1
                $definition = $generator->getDefinition();
410 1
                if (! isset($definition['class'])) {
411
                    throw InvalidCustomGenerator::onClassNotConfigured();
412
                }
413 1
                if (! class_exists($definition['class'])) {
414
                    throw InvalidCustomGenerator::onMissingClass($definition);
415
                }
416
417 1
                break;
418
419 282
            case GeneratorType::IDENTITY:
420
            case GeneratorType::NONE:
421
            case GeneratorType::UUID:
422 282
                break;
423
424
            default:
425
                throw UnknownGeneratorType::create($generator->getType());
426
        }
427 289
    }
428
429
    /**
430
     * {@inheritDoc}
431
     */
432 198
    protected function getDriver() : Driver\MappingDriver
433
    {
434 198
        return $this->driver;
435
    }
436
437
    /**
438
     * {@inheritDoc}
439
     */
440
    protected function isEntity(ClassMetadata $class) : bool
441
    {
442
        return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false;
443
    }
444
445 289
    private function getTargetPlatform() : Platforms\AbstractPlatform
446
    {
447 289
        if (! $this->targetPlatform) {
448 289
            $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
449
        }
450
451 289
        return $this->targetPlatform;
452
    }
453
454 364
    private function buildValueGenerationPlan(ClassMetadata $class) : void
455
    {
456 364
        $executors = $this->buildValueGenerationExecutorList($class);
457
458 364
        switch (count($executors)) {
459 364
            case 0:
460 91
                $class->setValueGenerationPlan(new NoopValueGenerationPlan());
461 91
                break;
462
463 304
            case 1:
464 299
                $class->setValueGenerationPlan(new SingleValueGenerationPlan($class, $executors[0]));
465 299
                break;
466
467
            default:
468 18
                $class->setValueGenerationPlan(new CompositeValueGenerationPlan($class, $executors));
469 18
                break;
470
        }
471 364
    }
472
473
    /**
474
     * @return ValueGenerationExecutor[]
475
     */
476 364
    private function buildValueGenerationExecutorList(ClassMetadata $class) : array
477
    {
478 364
        $executors = [];
479
480 364
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
481 362
            $executor = $this->buildValueGenerationExecutorForProperty($class, $property);
482
483 362
            if ($executor instanceof ValueGenerationExecutor) {
484 362
                $executors[] = $executor;
485
            }
486
        }
487
488 364
        return $executors;
489
    }
490
491 362
    private function buildValueGenerationExecutorForProperty(
492
        ClassMetadata $class,
493
        Property $property
494
    ) : ?ValueGenerationExecutor {
495 362
        if ($property instanceof LocalColumnMetadata && $property->hasValueGenerator()) {
496 288
            return new ColumnValueGeneratorExecutor($property, $this->createPropertyValueGenerator($class, $property));
497
        }
498
499 331
        if ($property instanceof ToOneAssociationMetadata && $property->isPrimaryKey()) {
500 41
            return new AssociationValueGeneratorExecutor();
501
        }
502
503 327
        return null;
504
    }
505
506 288
    private function createPropertyValueGenerator(
507
        ClassMetadata $class,
508
        LocalColumnMetadata $property
509
    ) : Sequencing\Generator {
510 288
        $platform = $this->getTargetPlatform();
511
512 288
        switch ($property->getValueGenerator()->getType()) {
513 288
            case GeneratorType::IDENTITY:
514 281
                $sequenceName = null;
515
516
                // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
517 281
                if ($platform->usesSequenceEmulatedIdentityColumns()) {
518
                    $sequencePrefix = $platform->getSequencePrefix($class->getTableName(), $class->getSchemaName());
519
                    $idSequenceName = $platform->getIdentitySequenceName($sequencePrefix, $property->getColumnName());
520
                    $sequenceName   = $platform->quoteIdentifier($platform->fixSchemaElementName($idSequenceName));
521
                }
522
523 281
                return $property->getTypeName() === 'bigint'
524 1
                    ? new Sequencing\BigIntegerIdentityGenerator($sequenceName)
525 281
                    : new Sequencing\IdentityGenerator($sequenceName);
526
527 7
            case GeneratorType::SEQUENCE:
528 6
                $definition = $property->getValueGenerator()->getDefinition();
529 6
                return new Sequencing\SequenceGenerator(
530 6
                    $platform->quoteIdentifier($definition['sequenceName']),
531 6
                    $definition['allocationSize']
532
                );
533
                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...
534
535 1
            case GeneratorType::UUID:
536
                return new Sequencing\UuidGenerator();
537
                break;
538
539 1
            case GeneratorType::CUSTOM:
540 1
                $class = $property->getValueGenerator()->getDefinition()['class'];
541 1
                return new $class();
542
                break;
543
        }
544
    }
545
}
546