Failed Conditions
Pull Request — master (#7210)
by Michael
12:25
created

MappingException   F

Complexity

Total Complexity 71

Size/Duplication

Total Lines 844
Duplicated Lines 0 %

Test Coverage

Coverage 34.62%

Importance

Changes 0
Metric Value
dl 0
loc 844
ccs 72
cts 208
cp 0.3462
rs 2.1052
c 0
b 0
f 0
wmc 71

67 Methods

Rating   Name   Duplication   Size   Complexity  
A oneToManyRequiresMappedBy() 0 3 1
A nameIsMandatoryForSqlResultSetMapping() 0 3 1
A joinTableRequired() 0 3 1
A missingRequiredOption() 0 9 2
A missingResultSetMappingFieldName() 0 3 1
A missingQueryMapping() 0 3 1
A invalidMapping() 0 3 1
A illegalOrphanRemovalOnIdentifierAssociation() 0 7 1
A invalidOverrideFieldType() 0 3 1
A mappingNotFound() 0 3 1
A compositeKeyAssignedIdGeneratorRequired() 0 3 1
A missingResultSetMappingEntity() 0 3 1
A mappedClassNotPartOfDiscriminatorMap() 0 6 1
A infiniteEmbeddableNesting() 0 8 1
A classNotFoundInNamespaces() 0 7 1
A generatorNotAllowedWithCompositeId() 0 3 1
A noSingleAssociationJoinColumnFound() 0 3 1
A sqlConversionNotAllowedForPrimaryKeyProperties() 0 9 1
A cannotVersionIdField() 0 3 1
A missingSequenceName() 0 4 1
A resultMappingNotFound() 0 3 1
A invalidCascadeOption() 0 11 1
A missingEmbeddedClass() 0 3 1
A mappingFileNotFound() 0 3 1
A duplicateColumnName() 0 3 1
A invalidDiscriminatorColumnType() 0 3 1
A invalidOverridePropertyType() 0 3 1
A classIsNotAValidEntityOrMappedSuperClass() 0 15 2
A noIdDefined() 0 3 1
A unsupportedOptimisticLockingType() 0 3 1
A duplicateQueryMapping() 0 3 1
A nameIsMandatoryForDiscriminatorColumns() 0 3 1
A queryNotFound() 0 3 1
A missingDiscriminatorColumn() 0 3 1
A invalidOverrideFieldName() 0 3 1
A invalidOverrideVersionField() 0 3 1
A reflectionFailure() 0 3 1
A singleIdNotAllowedOnCompositePrimaryKey() 0 3 1
A identifierRequired() 0 15 2
A cannotMapCompositePrimaryKeyEntitiesAsForeignId() 0 4 1
A missingTargetEntity() 0 3 1
A joinColumnMustPointToMappedField() 0 4 1
A noFieldNameFoundForColumn() 0 7 1
A duplicateEntityListener() 0 3 1
A invalidTargetEntityClass() 0 3 1
A illegalToManyAssociationOnMappedSuperclass() 0 3 1
A illegalInverseIdentifierAssociation() 0 3 1
A illegalToManyIdentifierAssociation() 0 3 1
A missingDiscriminatorMap() 0 3 1
A noInheritanceOnMappedSuperClass() 0 3 1
A invalidFetchMode() 0 3 1
A propertyTypeIsRequired() 0 3 1
A invalidInheritanceType() 0 3 1
A entityListenerMethodNotFound() 0 3 1
A missingFieldName() 0 3 1
A pathRequired() 0 4 1
A missingSourceEntity() 0 3 1
A fileMappingDriversRequireConfiguredDirectoryPath() 0 9 2
A duplicateResultSetMapping() 0 3 1
A illegalOrphanRemoval() 0 4 1
A sqlConversionNotAllowedForIdentifiers() 0 9 1
A tableIdGeneratorNotImplemented() 0 3 1
A invalidClassInDiscriminatorMap() 0 7 1
A lifecycleCallbackMethodNotFound() 0 3 1
A entityListenerClassNotFound() 0 3 1
A duplicateProperty() 0 7 1
A duplicateDiscriminatorEntry() 0 12 1

How to fix   Complexity   

Complex Class

Complex classes like MappingException 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 MappingException, 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\ORM\Exception\ORMException;
8
use function array_keys;
9
use function array_map;
10
use function array_values;
11
use function get_parent_class;
12
use function implode;
13
use function sprintf;
14
15
/**
16
 * A MappingException indicates that something is wrong with the mapping setup.
17
 *
18
 * @todo Split into specific exceptions and change to interface.
19
 */
20
final class MappingException extends \LogicException implements ORMException
21
{
22
    /**
23
     * @return MappingException
24
     */
25
    public static function pathRequired()
26
    {
27
        return new self('Specifying the paths to your entities is required ' .
28
            'in the AnnotationDriver to retrieve all class names.');
29
    }
30
31
    /**
32
     * @param string $entityName
33
     *
34
     * @return MappingException
35
     */
36 4
    public static function identifierRequired($entityName)
37
    {
38 4
        $parent = get_parent_class($entityName);
39
40 4
        if ($parent !== false) {
41 2
            return new self(sprintf(
42 2
                'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
43 2
                $entityName,
44 2
                $parent
45
            ));
46
        }
47
48 2
        return new self(sprintf(
49 2
            'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
50 2
            $entityName
51
        ));
52
    }
53
54
    /**
55
     * @param string $entityName
56
     * @param string $type
57
     *
58
     * @return MappingException
59
     */
60
    public static function invalidInheritanceType($entityName, $type)
61
    {
62
        return new self(sprintf("The inheritance type '%s' specified for '%s' does not exist.", $type, $entityName));
63
    }
64
65
    /**
66
     * @return MappingException
67
     */
68
    public static function generatorNotAllowedWithCompositeId()
69
    {
70
        return new self("Id generators can't be used with a composite id.");
71
    }
72
73
    /**
74
     * @param string $entity
75
     *
76
     * @return MappingException
77
     */
78 1
    public static function missingFieldName($entity)
79
    {
80 1
        return new self(sprintf("The field or association mapping misses the 'fieldName' attribute in entity '%s'.", $entity));
81
    }
82
83
    /**
84
     * @param string $fieldName
85
     *
86
     * @return MappingException
87
     */
88
    public static function missingTargetEntity($fieldName)
89
    {
90
        return new self(sprintf("The association mapping '%s' misses the 'targetEntity' attribute.", $fieldName));
91
    }
92
93
    /**
94
     * @param string $fieldName
95
     *
96
     * @return MappingException
97
     */
98
    public static function missingSourceEntity($fieldName)
99
    {
100
        return new self(sprintf("The association mapping '%s' misses the 'sourceEntity' attribute.", $fieldName));
101
    }
102
103
    /**
104
     * @param string $fieldName
105
     *
106
     * @return MappingException
107
     */
108
    public static function missingEmbeddedClass($fieldName)
109
    {
110
        return new self(sprintf("The embed mapping '%s' misses the 'class' attribute.", $fieldName));
111
    }
112
113
    /**
114
     * @param string $entityName
115
     * @param string $fileName
116
     *
117
     * @return MappingException
118
     */
119
    public static function mappingFileNotFound($entityName, $fileName)
120
    {
121
        return new self(sprintf("No mapping file found named '%s' for class '%s'.", $fileName, $entityName));
122
    }
123
124
    /**
125
     * Exception for invalid property name override.
126
     *
127
     * @param string $className The entity's name.
128
     * @param string $fieldName
129
     *
130
     * @return MappingException
131
     */
132 2
    public static function invalidOverrideFieldName($className, $fieldName)
133
    {
134 2
        return new self(sprintf("Invalid field override named '%s' for class '%s'.", $fieldName, $className));
135
    }
136
137
    /**
138
     * Exception for invalid property type override.
139
     *
140
     * @param string $className The entity's name.
141
     * @param string $fieldName
142
     *
143
     * @return MappingException
144
     */
145
    public static function invalidOverridePropertyType($className, $fieldName)
146
    {
147
        return new self(sprintf("Invalid property override named '%s' for class '%s'.", $fieldName, $className));
148
    }
149
150
    /**
151
     * Exception for invalid version property override.
152
     *
153
     * @param string $className The entity's name.
154
     * @param string $fieldName
155
     *
156
     * @return MappingException
157
     */
158
    public static function invalidOverrideVersionField($className, $fieldName)
159
    {
160
        return new self(sprintf("Invalid version field override named '%s' for class '%s'.", $fieldName, $className));
161
    }
162
163
    /**
164
     * Exception for invalid property type override.
165
     *
166
     * @param string $className The entity's name.
167
     * @param string $fieldName
168
     *
169
     * @return MappingException
170
     */
171
    public static function invalidOverrideFieldType($className, $fieldName)
172
    {
173
        return new self(sprintf("The column type of attribute '%s' on class '%s' could not be changed.", $fieldName, $className));
174
    }
175
176
    /**
177
     * @param string $className
178
     * @param string $fieldName
179
     *
180
     * @return MappingException
181
     */
182
    public static function mappingNotFound($className, $fieldName)
183
    {
184
        return new self(sprintf("No mapping found for field '%s' on class '%s'.", $fieldName, $className));
185
    }
186
187
    /**
188
     * @param string $className
189
     * @param string $queryName
190
     *
191
     * @return MappingException
192
     */
193
    public static function queryNotFound($className, $queryName)
194
    {
195
        return new self(sprintf("No query found named '%s' on class '%s'.", $queryName, $className));
196
    }
197
198
    /**
199
     * @param string $className
200
     * @param string $resultName
201
     *
202
     * @return MappingException
203
     */
204
    public static function resultMappingNotFound($className, $resultName)
205
    {
206
        return new self(sprintf("No result set mapping found named '%s' on class '%s'.", $resultName, $className));
207
    }
208
209
    /**
210
     * @param string $entity
211
     * @param string $queryName
212
     *
213
     * @return MappingException
214
     */
215
    public static function missingQueryMapping($entity, $queryName)
216
    {
217
        return new self('Query named "' . $queryName . '" in "' . $entity . ' requires a result class or result set mapping.');
218
    }
219
220
    /**
221
     * @param string $entity
222
     * @param string $resultName
223
     *
224
     * @return MappingException
225
     */
226
    public static function missingResultSetMappingEntity($entity, $resultName)
227
    {
228
        return new self('Result set mapping named "' . $resultName . '" in "' . $entity . ' requires a entity class name.');
229
    }
230
231
    /**
232
     * @param string $entity
233
     * @param string $resultName
234
     *
235
     * @return MappingException
236
     */
237
    public static function missingResultSetMappingFieldName($entity, $resultName)
238
    {
239
        return new self('Result set mapping named "' . $resultName . '" in "' . $entity . ' requires a field name.');
240
    }
241
242
    /**
243
     * @param string $className
244
     *
245
     * @return MappingException
246
     */
247
    public static function nameIsMandatoryForSqlResultSetMapping($className)
248
    {
249
        return new self(sprintf("Result set mapping name on entity class '%s' is not defined.", $className));
250
    }
251
252
    /**
253
     * @param string $fieldName
254
     *
255
     * @return MappingException
256
     */
257
    public static function oneToManyRequiresMappedBy($fieldName)
258
    {
259
        return new self(sprintf("OneToMany mapping on field '%s' requires the 'mappedBy' attribute.", $fieldName));
260
    }
261
262
    /**
263
     * @param string $fieldName
264
     *
265
     * @return MappingException
266
     */
267
    public static function joinTableRequired($fieldName)
268
    {
269
        return new self(sprintf("The mapping of field '%s' requires an the 'joinTable' attribute.", $fieldName));
270
    }
271
272
    /**
273
     * Called if a required option was not found but is required
274
     *
275
     * @param string $field          Which field cannot be processed?
276
     * @param string $expectedOption Which option is required
277
     * @param string $hint           Can optionally be used to supply a tip for common mistakes,
278
     *                               e.g. "Did you think of the plural s?"
279
     *
280
     * @return MappingException
281
     */
282
    public static function missingRequiredOption($field, $expectedOption, $hint = '')
283
    {
284
        $message = sprintf("The mapping of field '%s' is invalid: The option '%s' is required.", $field, $expectedOption);
285
286
        if (! empty($hint)) {
287
            $message .= ' (Hint: ' . $hint . ')';
288
        }
289
290
        return new self($message);
291
    }
292
293
    /**
294
     * Generic exception for invalid mappings.
295
     *
296
     * @param string $fieldName
297
     *
298
     * @return MappingException
299
     */
300
    public static function invalidMapping($fieldName)
301
    {
302
        return new self(sprintf("The mapping of field '%s' is invalid.", $fieldName));
303
    }
304
305
    /**
306
     * Exception for reflection exceptions - adds the entity name,
307
     * because there might be long classnames that will be shortened
308
     * within the stacktrace
309
     *
310
     * @param string $entity The entity's name
311
     *
312
     * @return MappingException
313
     */
314
    public static function reflectionFailure($entity, \ReflectionException $previousException)
315
    {
316
        return new self('An error occurred in ' . $entity, 0, $previousException);
317
    }
318
319
    /**
320
     * @param string $className
321
     * @param string $joinColumn
322
     *
323
     * @return MappingException
324
     */
325
    public static function joinColumnMustPointToMappedField($className, $joinColumn)
326
    {
327
        return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
328
            . $className . ' since it is referenced by a join column of another class.');
329
    }
330
331
    /**
332
     * @param string $className
333
     *
334
     * @return MappingException
335
     */
336 3
    public static function classIsNotAValidEntityOrMappedSuperClass($className)
337
    {
338 3
        $parent = get_parent_class($className);
339
340 3
        if ($parent !== false) {
341 1
            return new self(sprintf(
342 1
                'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
343 1
                $className,
344 1
                $parent
345
            ));
346
        }
347
348 2
        return new self(sprintf(
349 2
            'Class "%s" is not a valid entity or mapped super class.',
350 2
            $className
351
        ));
352
    }
353
354
    /**
355
     * @param string $className
356
     * @param string $propertyName
357
     *
358
     * @return MappingException
359
     */
360
    public static function propertyTypeIsRequired($className, $propertyName)
361
    {
362
        return new self("The attribute 'type' is required for the column description of property " . $className . '::$' . $propertyName . '.');
363
    }
364
365
    /**
366
     * @param string $className
367
     *
368
     * @return MappingException
369
     */
370
    public static function tableIdGeneratorNotImplemented($className)
371
    {
372
        return new self('TableIdGenerator is not yet implemented for use with class ' . $className);
373
    }
374
375
    /**
376
     * @param string $className
377
     *
378
     * @return MappingException
379
     */
380 3
    public static function duplicateProperty($className, Property $property)
381
    {
382 3
        return new self(sprintf(
383 3
            'Property "%s" in "%s" was already declared in "%s", but it must be declared only once',
384 3
            $property->getName(),
385 3
            $className,
386 3
            $property->getDeclaringClass()->getClassName()
387
        ));
388
    }
389
390
    /**
391
     * @param string $entity
392
     * @param string $queryName
393
     *
394
     * @return MappingException
395
     */
396
    public static function duplicateQueryMapping($entity, $queryName)
397
    {
398
        return new self('Query named "' . $queryName . '" in "' . $entity . '" was already declared, but it must be declared only once');
399
    }
400
401
    /**
402
     * @param string $entity
403
     * @param string $resultName
404
     *
405
     * @return MappingException
406
     */
407
    public static function duplicateResultSetMapping($entity, $resultName)
408
    {
409
        return new self('Result set mapping named "' . $resultName . '" in "' . $entity . '" was already declared, but it must be declared only once');
410
    }
411
412
    /**
413
     * @param string $entity
414
     *
415
     * @return MappingException
416
     */
417 1
    public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
418
    {
419 1
        return new self('Single id is not allowed on composite primary key in entity ' . $entity);
420
    }
421
422
    /**
423
     * @param string $entity
424
     *
425
     * @return MappingException
426
     */
427 1
    public static function noIdDefined($entity)
428
    {
429 1
        return new self('No ID defined for entity ' . $entity);
430
    }
431
432
    /**
433
     * @param string $unsupportedType
434
     *
435
     * @return MappingException
436
     */
437 1
    public static function unsupportedOptimisticLockingType($unsupportedType)
438
    {
439 1
        return new self('Locking type "' . $unsupportedType . '" is not supported by Doctrine.');
440
    }
441
442
    /**
443
     * @param string|null $path
444
     *
445
     * @return MappingException
446
     */
447
    public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
448
    {
449
        if (! empty($path)) {
450
            $path = '[' . $path . ']';
451
        }
452
453
        return new self(
454
            'File mapping drivers must have a valid directory path, ' .
455
            'however the given path ' . $path . ' seems to be incorrect!'
456
        );
457
    }
458
459
    /**
460
     * Returns an exception that indicates that a class used in a discriminator map does not exist.
461
     * An example would be an outdated (maybe renamed) classname.
462
     *
463
     * @param string $className   The class that could not be found
464
     * @param string $owningClass The class that declares the discriminator map.
465
     *
466
     * @return MappingException
467
     */
468
    public static function invalidClassInDiscriminatorMap($className, $owningClass)
469
    {
470
        return new self(sprintf(
471
            "Entity class '%s' used in the discriminator map of class '%s' " .
472
            'does not exist.',
473
            $className,
474
            $owningClass
475
        ));
476
    }
477
478
    /**
479
     * @param string   $className
480
     * @param string[] $entries
481
     * @param string[] $map
482
     *
483
     * @return MappingException
484
     */
485
    public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
486
    {
487
        return new self(
488
            'The entries ' . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
489
            'If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. ' .
490
            'The entries of the current map are: @DiscriminatorMap({' . implode(', ', array_map(
491
                function ($a, $b) {
492
                    return sprintf("'%s': '%s'", $a, $b);
493
                },
494
                array_keys($map),
495
                array_values($map)
496
            )) . '})'
497
        );
498
    }
499
500
    /**
501
     * @param string $className
502
     *
503
     * @return MappingException
504
     */
505
    public static function missingDiscriminatorMap($className)
506
    {
507
        return new self(sprintf("Entity class '%s' is using inheritance but no discriminator map was defined.", $className));
508
    }
509
510
    /**
511
     * @param string $className
512
     *
513
     * @return MappingException
514
     */
515
    public static function missingDiscriminatorColumn($className)
516
    {
517
        return new self(sprintf("Entity class '%s' is using inheritance but no discriminator column was defined.", $className));
518
    }
519
520
    /**
521
     * @param string $type
522
     *
523
     * @return MappingException
524
     */
525
    public static function invalidDiscriminatorColumnType($type)
526
    {
527
        return new self(sprintf("Discriminator column type is not allowed to be '%s'. 'string' or 'integer' type variables are suggested!", $type));
528
    }
529
530
    /**
531
     * @param string $className
532
     *
533
     * @return MappingException
534
     */
535
    public static function nameIsMandatoryForDiscriminatorColumns($className)
536
    {
537
        return new self(sprintf("Discriminator column name on entity class '%s' is not defined.", $className));
538
    }
539
540
    /**
541
     * @param string $className
542
     * @param string $fieldName
543
     *
544
     * @return MappingException
545
     */
546
    public static function cannotVersionIdField($className, $fieldName)
547
    {
548
        return new self(sprintf("Setting Id field '%s' as versionable in entity class '%s' is not supported.", $fieldName, $className));
549
    }
550
551
    /**
552
     * @param string $className
553
     *
554
     * @return MappingException
555
     */
556
    public static function sqlConversionNotAllowedForPrimaryKeyProperties($className, Property $property)
557
    {
558
        return new self(sprintf(
559
            'It is not possible to set id field "%s" to type "%s" in entity class "%s". ' .
560
            'The type "%s" requires conversion SQL which is not allowed for identifiers.',
561
            $property->getName(),
562
            $property->getTypeName(),
0 ignored issues
show
Bug introduced by
The method getTypeName() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as 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

562
            $property->/** @scrutinizer ignore-call */ 
563
                       getTypeName(),
Loading history...
563
            $className,
564
            $property->getTypeName()
565
        ));
566
    }
567
568
    /**
569
     * @param string $className
570
     * @param string $fieldName
571
     * @param string $type
572
     *
573
     * @return MappingException
574
     */
575
    public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
576
    {
577
        return new self(sprintf(
578
            "It is not possible to set id field '%s' to type '%s' in entity class '%s'. The type '%s' "
579
                . 'requires conversion SQL which is not allowed for identifiers.',
580
            $fieldName,
581
            $type,
582
            $className,
583
            $type
584
        ));
585
    }
586
587
    /**
588
     * @param string $className
589
     * @param string $columnName
590
     *
591
     * @return MappingException
592
     */
593 3
    public static function duplicateColumnName($className, $columnName)
594
    {
595 3
        return new self("Duplicate definition of column '" . $columnName . "' on entity '" . $className . "' in a field or discriminator column mapping.");
596
    }
597
598
    /**
599
     * @param string $className
600
     * @param string $field
601
     *
602
     * @return MappingException
603
     */
604 1
    public static function illegalToManyAssociationOnMappedSuperclass($className, $field)
605
    {
606 1
        return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '" . $className . '#' . $field . "'.");
607
    }
608
609
    /**
610
     * @param string $className
611
     * @param string $targetEntity
612
     * @param string $targetField
613
     *
614
     * @return MappingException
615
     */
616
    public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
617
    {
618
        return new self("It is not possible to map entity '" . $className . "' with a composite primary key " .
619
            "as part of the primary key of another entity '" . $targetEntity . '#' . $targetField . "'.");
620
    }
621
622
    /**
623
     * @param string $className
624
     * @param string $field
625
     *
626
     * @return MappingException
627
     */
628
    public static function noSingleAssociationJoinColumnFound($className, $field)
629
    {
630
        return new self(sprintf("'%s#%s' is not an association with a single join column.", $className, $field));
631
    }
632
633
    /**
634
     * @param string $className
635
     * @param string $column
636
     *
637
     * @return MappingException
638
     */
639
    public static function noFieldNameFoundForColumn($className, $column)
640
    {
641
        return new self(sprintf(
642
            "Cannot find a field on '%s' that is mapped to column '%s'. Either the "
643
                . 'field does not exist or an association exists but it has multiple join columns.',
644
            $className,
645
            $column
646
        ));
647
    }
648
649
    /**
650
     * @param string $className
651
     * @param string $field
652
     *
653
     * @return MappingException
654
     */
655 1
    public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
656
    {
657 1
        return new self(sprintf(
658
            'The orphan removal option is not allowed on an association that is '
659 1
                . "part of the identifier in '%s#%s'.",
660 1
            $className,
661 1
            $field
662
        ));
663
    }
664
665
    /**
666
     * @param string $className
667
     * @param string $field
668
     *
669
     * @return MappingException
670
     */
671
    public static function illegalOrphanRemoval($className, $field)
672
    {
673
        return new self('Orphan removal is only allowed on one-to-one and one-to-many ' .
674
            'associations, but ' . $className . '#' . $field . ' is not.');
675
    }
676
677
    /**
678
     * @param string $className
679
     * @param string $field
680
     *
681
     * @return MappingException
682
     */
683 1
    public static function illegalInverseIdentifierAssociation($className, $field)
684
    {
685 1
        return new self(sprintf("An inverse association is not allowed to be identifier in '%s#%s'.", $className, $field));
686
    }
687
688
    /**
689
     * @param string $className
690
     * @param string $field
691
     *
692
     * @return MappingException
693
     */
694 1
    public static function illegalToManyIdentifierAssociation($className, $field)
695
    {
696 1
        return new self(sprintf("Many-to-many or one-to-many associations are not allowed to be identifier in '%s#%s'.", $className, $field));
697
    }
698
699
    /**
700
     * @param string $className
701
     *
702
     * @return MappingException
703
     */
704
    public static function noInheritanceOnMappedSuperClass($className)
705
    {
706
        return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'.");
707
    }
708
709
    /**
710
     * @param string $className
711
     * @param string $rootClassName
712
     *
713
     * @return MappingException
714
     */
715 1
    public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
716
    {
717 1
        return new self(
718 1
            "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
719 1
            "to be properly mapped in the inheritance hierarchy. Alternatively you can make '" . $className . "' an abstract class " .
720 1
            'to avoid this exception from occurring.'
721
        );
722
    }
723
724
    /**
725
     * @param string $className
726
     * @param string $methodName
727
     *
728
     * @return MappingException
729
     */
730 1
    public static function lifecycleCallbackMethodNotFound($className, $methodName)
731
    {
732 1
        return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
733
    }
734
735
    /**
736
     * @param string $listenerName
737
     * @param string $className
738
     *
739
     * @return \Doctrine\ORM\Mapping\MappingException
740
     */
741 1
    public static function entityListenerClassNotFound($listenerName, $className)
742
    {
743 1
        return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className));
744
    }
745
746
    /**
747
     * @param string $listenerName
748
     * @param string $methodName
749
     * @param string $className
750
     *
751
     * @return \Doctrine\ORM\Mapping\MappingException
752
     */
753 1
    public static function entityListenerMethodNotFound($listenerName, $methodName, $className)
754
    {
755 1
        return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName));
756
    }
757
758
    /**
759
     * @param string $listenerName
760
     * @param string $methodName
761
     * @param string $className
762
     *
763
     * @return \Doctrine\ORM\Mapping\MappingException
764
     */
765 1
    public static function duplicateEntityListener($listenerName, $methodName, $className)
766
    {
767 1
        return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className));
768
    }
769
770
    /**
771
     * @param string $className
772
     * @param string $annotation
773
     *
774
     * @return MappingException
775
     */
776
    public static function invalidFetchMode($className, $annotation)
777
    {
778
        return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
779
    }
780
781
    /**
782
     * @param string $className
783
     *
784
     * @return MappingException
785
     */
786
    public static function compositeKeyAssignedIdGeneratorRequired($className)
787
    {
788
        return new self("Entity '" . $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
789
    }
790
791
    /**
792
     * @param string $targetEntity
793
     * @param string $sourceEntity
794
     * @param string $associationName
795
     *
796
     * @return MappingException
797
     */
798 1
    public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
799
    {
800 1
        return new self("The target-entity '" . $targetEntity . "' cannot be found in '" . $sourceEntity . '#' . $associationName . "'.");
801
    }
802
803
    /**
804
     * @param string[] $cascades
805
     * @param string   $className
806
     * @param string   $propertyName
807
     *
808
     * @return MappingException
809
     */
810 1
    public static function invalidCascadeOption(array $cascades, $className, $propertyName)
811
    {
812
        $cascades = implode(', ', array_map(function ($e) {
813 1
            return "'" . $e . "'";
814 1
        }, $cascades));
815
816 1
        return new self(sprintf(
817 1
            "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', and 'refresh'",
818 1
            $className,
819 1
            $propertyName,
820 1
            $cascades
821
        ));
822
    }
823
824
    /**
825
     * @param string $className
826
     *
827
     * @return MappingException
828
     */
829
    public static function missingSequenceName($className)
830
    {
831
        return new self(
832
            sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className)
833
        );
834
    }
835
836
    /**
837
     * @param string $className
838
     * @param string $propertyName
839
     *
840
     * @return MappingException
841
     */
842
    public static function infiniteEmbeddableNesting($className, $propertyName)
843
    {
844
        return new self(
845
            sprintf(
846
                'Infinite nesting detected for embedded property %s::%s. ' .
847
                'You cannot embed an embeddable from the same type inside an embeddable.',
848
                $className,
849
                $propertyName
850
            )
851
        );
852
    }
853
854
    /**
855
     * @param string[] $namespaces
856
     */
857
    public static function classNotFoundInNamespaces(string $className, array $namespaces) : self
858
    {
859
        return new self(
860
            sprintf(
861
                'Class %s not found in namespaces %s.' .
862
                $className,
863
                implode(', ', $namespaces)
864
            )
865
        );
866
    }
867
}
868