Completed
Pull Request — 2.7 (#6728)
by Luís
11:01
created

singleIdNotAllowedOnCompositePrimaryKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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;
21
22
use LibXMLError;
23
24
/**
25
 * A MappingException indicates that something is wrong with the mapping setup.
26
 *
27
 * @since 2.0
28
 */
29
class MappingException extends \Doctrine\ORM\ORMException
30
{
31
    /**
32
     * @return MappingException
33
     */
34
    public static function pathRequired()
35
    {
36
        return new self("Specifying the paths to your entities is required ".
37
            "in the AnnotationDriver to retrieve all class names.");
38
    }
39
40
    /**
41
     * @param string $entityName
42
     *
43
     * @return MappingException
44
     */
45 6
    public static function identifierRequired($entityName)
46
    {
47 6
        if (false !== ($parent = get_parent_class($entityName))) {
48 6
            return new self(sprintf(
49 6
                'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
50 6
                $entityName, $parent
51
            ));
52
        }
53
54
        return new self(sprintf(
55
            'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
56
            $entityName
57
        ));
58
59
    }
60
61
    /**
62
     * @param string $entityName
63
     * @param string $type
64
     *
65
     * @return MappingException
66
     */
67
    public static function invalidInheritanceType($entityName, $type)
68
    {
69
        return new self("The inheritance type '$type' specified for '$entityName' does not exist.");
70
    }
71
72
    /**
73
     * @return MappingException
74
     */
75
    public static function generatorNotAllowedWithCompositeId()
76
    {
77
        return new self("Id generators can't be used with a composite id.");
78
    }
79
80
    /**
81
     * @param string $entity
82
     *
83
     * @return MappingException
84
     */
85 1
    public static function missingFieldName($entity)
86
    {
87 1
        return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
88
    }
89
90
    /**
91
     * @param string $fieldName
92
     *
93
     * @return MappingException
94
     */
95
    public static function missingTargetEntity($fieldName)
96
    {
97
        return new self("The association mapping '$fieldName' misses the 'targetEntity' attribute.");
98
    }
99
100
    /**
101
     * @param string $fieldName
102
     *
103
     * @return MappingException
104
     */
105
    public static function missingSourceEntity($fieldName)
106
    {
107
        return new self("The association mapping '$fieldName' misses the 'sourceEntity' attribute.");
108
    }
109
110
    /**
111
     * @param string $fieldName
112
     *
113
     * @return MappingException
114
     */
115 1
    public static function missingEmbeddedClass($fieldName)
116
    {
117 1
        return new self("The embed mapping '$fieldName' misses the 'class' attribute.");
118
    }
119
120
    /**
121
     * @param string $entityName
122
     * @param string $fileName
123
     *
124
     * @return MappingException
125
     */
126
    public static function mappingFileNotFound($entityName, $fileName)
127
    {
128
        return new self("No mapping file found named '$fileName' for class '$entityName'.");
129
    }
130
131
    /**
132
     * Exception for invalid property name override.
133
     *
134
     * @param string $className The entity's name.
135
     * @param string $fieldName
136
     *
137
     * @return MappingException
138
     */
139 2
    public static function invalidOverrideFieldName($className, $fieldName)
140
    {
141 2
        return new self("Invalid field override named '$fieldName' for class '$className'.");
142
    }
143
144
    /**
145
     * Exception for invalid property type override.
146
     *
147
     * @param string $className The entity's name.
148
     * @param string $fieldName
149
     *
150
     * @return MappingException
151
     */
152 1
    public static function invalidOverrideFieldType($className, $fieldName)
153
    {
154 1
        return new self("The column type of attribute '$fieldName' on class '$className' could not be changed.");
155
    }
156
157
    /**
158
     * @param string $className
159
     * @param string $fieldName
160
     *
161
     * @return MappingException
162
     */
163 1
    public static function mappingNotFound($className, $fieldName)
164
    {
165 1
        return new self("No mapping found for field '$fieldName' on class '$className'.");
166
    }
167
168
    /**
169
     * @param string $className
170
     * @param string $queryName
171
     *
172
     * @return MappingException
173
     */
174 1
    public static function queryNotFound($className, $queryName)
175
    {
176 1
        return new self("No query found named '$queryName' on class '$className'.");
177
    }
178
179
    /**
180
     * @param string $className
181
     * @param string $resultName
182
     *
183
     * @return MappingException
184
     */
185
    public static function resultMappingNotFound($className, $resultName)
186
    {
187
        return new self("No result set mapping found named '$resultName' on class '$className'.");
188
    }
189
190
    /**
191
     * @param string $entity
192
     * @param string $queryName
193
     *
194
     * @return MappingException
195
     */
196
    public static function emptyQueryMapping($entity, $queryName)
197
    {
198
        return new self('Query named "'.$queryName.'" in "'.$entity.'" could not be empty.');
199
    }
200
201
    /**
202
     * @param string $className
203
     *
204
     * @return MappingException
205
     */
206 2
    public static function nameIsMandatoryForQueryMapping($className)
207
    {
208 2
        return new self("Query name on entity class '$className' is not defined.");
209
    }
210
211
    /**
212
     * @param string $entity
213
     * @param string $queryName
214
     *
215
     * @return MappingException
216
     */
217
    public static function missingQueryMapping($entity, $queryName)
218
    {
219
        return new self('Query named "'.$queryName.'" in "'.$entity.' requires a result class or result set mapping.');
220
    }
221
222
    /**
223
     * @param string $entity
224
     * @param string $resultName
225
     *
226
     * @return MappingException
227
     */
228 1
    public static function missingResultSetMappingEntity($entity, $resultName)
229
    {
230 1
        return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a entity class name.');
231
    }
232
233
    /**
234
     * @param string $entity
235
     * @param string $resultName
236
     *
237
     * @return MappingException
238
     */
239
    public static function missingResultSetMappingFieldName($entity, $resultName)
240
    {
241
        return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a field name.');
242
    }
243
244
    /**
245
     * @param string $className
246
     *
247
     * @return MappingException
248
     */
249
    public static function nameIsMandatoryForSqlResultSetMapping($className)
250
    {
251
        return new self("Result set mapping name on entity class '$className' is not defined.");
252
    }
253
254
    /**
255
     * @param string $fieldName
256
     *
257
     * @return MappingException
258
     */
259
    public static function oneToManyRequiresMappedBy($fieldName)
260
    {
261
        return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
262
    }
263
264
    /**
265
     * @param string $fieldName
266
     *
267
     * @return MappingException
268
     */
269
    public static function joinTableRequired($fieldName)
270
    {
271
        return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute.");
272
    }
273
274
    /**
275
     * Called if a required option was not found but is required
276
     *
277
     * @param string $field          Which field cannot be processed?
278
     * @param string $expectedOption Which option is required
279
     * @param string $hint           Can optionally be used to supply a tip for common mistakes,
280
     *                               e.g. "Did you think of the plural s?"
281
     *
282
     * @return MappingException
283
     */
284
    static function missingRequiredOption($field, $expectedOption, $hint = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
285
    {
286
        $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required.";
287
288
        if ( ! empty($hint)) {
289
            $message .= ' (Hint: ' . $hint . ')';
290
        }
291
292
        return new self($message);
293
    }
294
295
    /**
296
     * Generic exception for invalid mappings.
297
     *
298
     * @param string $fieldName
299
     *
300
     * @return MappingException
301
     */
302
    public static function invalidMapping($fieldName)
303
    {
304
        return new self("The mapping of field '$fieldName' is invalid.");
305
    }
306
307
    /**
308
     * Exception for reflection exceptions - adds the entity name,
309
     * because there might be long classnames that will be shortened
310
     * within the stacktrace
311
     *
312
     * @param string               $entity            The entity's name
313
     * @param \ReflectionException $previousException
314
     *
315
     * @return MappingException
316
     */
317
    public static function reflectionFailure($entity, \ReflectionException $previousException)
318
    {
319
        return new self('An error occurred in ' . $entity, 0, $previousException);
320
    }
321
322
    /**
323
     * @param string $className
324
     * @param string $joinColumn
325
     *
326
     * @return MappingException
327
     */
328
    public static function joinColumnMustPointToMappedField($className, $joinColumn)
329
    {
330
        return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
331
            . $className . ' since it is referenced by a join column of another class.');
332
    }
333
334
    /**
335
     * @param string $className
336
     *
337
     * @return MappingException
338
     */
339 5
    public static function classIsNotAValidEntityOrMappedSuperClass($className)
340
    {
341 5
        if (false !== ($parent = get_parent_class($className))) {
342 3
            return new self(sprintf(
343 3
                'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
344 3
                $className, $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 $entity    The entity's name.
377
     * @param string $fieldName The name of the field that was already declared.
378
     *
379
     * @return MappingException
380
     */
381 2
    public static function duplicateFieldMapping($entity, $fieldName)
382
    {
383 2
        return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
384
    }
385
386
    /**
387
     * @param string $entity
388
     * @param string $fieldName
389
     *
390
     * @return MappingException
391
     */
392 1
    public static function duplicateAssociationMapping($entity, $fieldName)
393
    {
394 1
        return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
395
    }
396
397
    /**
398
     * @param string $entity
399
     * @param string $queryName
400
     *
401
     * @return MappingException
402
     */
403 2
    public static function duplicateQueryMapping($entity, $queryName)
404
    {
405 2
        return new self('Query named "'.$queryName.'" in "'.$entity.'" was already declared, but it must be declared only once');
406
    }
407
408
    /**
409
     * @param string $entity
410
     * @param string $resultName
411
     *
412
     * @return MappingException
413
     */
414 1
    public static function duplicateResultSetMapping($entity, $resultName)
415
    {
416 1
        return new self('Result set mapping named "'.$resultName.'" in "'.$entity.'" was already declared, but it must be declared only once');
417
    }
418
419
    /**
420
     * @param string $entity
421
     *
422
     * @return MappingException
423
     */
424 1
    public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
425
    {
426 1
        return new self('Single id is not allowed on composite primary key in entity '.$entity);
427
    }
428
429
    /**
430
     * @param string $entity
431
     *
432
     * @return MappingException
433
     */
434 1
    public static function noIdDefined($entity)
435
    {
436 1
        return new self('No ID defined for entity ' . $entity);
437
    }
438
439
    /**
440
     * @param string $entity
441
     * @param string $fieldName
442
     * @param string $unsupportedType
443
     *
444
     * @return MappingException
445
     */
446 1
    public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType)
447
    {
448 1
        return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
449 1
            .'is not supported by Doctrine.'
450
        );
451
    }
452
453
    /**
454
     * @param string|null $path
455
     *
456
     * @return MappingException
457
     */
458
    public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
459
    {
460
        if ( ! empty($path)) {
461
            $path = '[' . $path . ']';
462
        }
463
464
        return new self(
465
            'File mapping drivers must have a valid directory path, ' .
466
            'however the given path ' . $path . ' seems to be incorrect!'
467
        );
468
    }
469
470
    /**
471
     * Returns an exception that indicates that a class used in a discriminator map does not exist.
472
     * An example would be an outdated (maybe renamed) classname.
473
     *
474
     * @param string $className   The class that could not be found
475
     * @param string $owningClass The class that declares the discriminator map.
476
     *
477
     * @return MappingException
478
     */
479
    public static function invalidClassInDiscriminatorMap($className, $owningClass)
480
    {
481
        return new self(
482
            "Entity class '$className' used in the discriminator map of class '$owningClass' ".
483
            "does not exist."
484
        );
485
    }
486
487
    /**
488
     * @param string $className
489
     * @param array  $entries
490
     * @param array  $map
491
     *
492
     * @return MappingException
493
     */
494
    public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
495
    {
496
        return new self(
497
            "The entries " . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
498
            "If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. " .
499
            "The entries of the current map are: @DiscriminatorMap({" . implode(', ', array_map(
500
                function($a, $b) { return "'$a': '$b'"; }, array_keys($map), array_values($map)
501
            )) . "})"
502
        );
503
    }
504
505
    /**
506
     * @param string $className
507
     *
508
     * @return MappingException
509
     */
510
    public static function missingDiscriminatorMap($className)
511
    {
512
        return new self("Entity class '$className' is using inheritance but no discriminator map was defined.");
513
    }
514
515
    /**
516
     * @param string $className
517
     *
518
     * @return MappingException
519
     */
520
    public static function missingDiscriminatorColumn($className)
521
    {
522
        return new self("Entity class '$className' is using inheritance but no discriminator column was defined.");
523
    }
524
525
    /**
526
     * @param string $className
527
     * @param string $type
528
     *
529
     * @return MappingException
530
     */
531
    public static function invalidDiscriminatorColumnType($className, $type)
532
    {
533
        return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
534
    }
535
536
    /**
537
     * @param string $className
538
     *
539
     * @return MappingException
540
     */
541 1
    public static function nameIsMandatoryForDiscriminatorColumns($className)
542
    {
543 1
        return new self("Discriminator column name on entity class '$className' is not defined.");
544
    }
545
546
    /**
547
     * @param string $className
548
     * @param string $fieldName
549
     *
550
     * @return MappingException
551
     */
552
    public static function cannotVersionIdField($className, $fieldName)
553
    {
554
        return new self("Setting Id field '$fieldName' as versionable in entity class '$className' is not supported.");
555
    }
556
557
    /**
558
     * @param string $className
559
     * @param string $fieldName
560
     * @param string $type
561
     *
562
     * @return MappingException
563
     */
564
    public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
565
    {
566
        return new self("It is not possible to set id field '$fieldName' to type '$type' in entity class '$className'. The type '$type' requires conversion SQL which is not allowed for identifiers.");
567
    }
568
569
    /**
570
     * @param string $className
571
     * @param string $columnName
572
     *
573
     * @return MappingException
574
     */
575 3
    public static function duplicateColumnName($className, $columnName)
576
    {
577 3
        return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
578
    }
579
580
    /**
581
     * @param string $className
582
     * @param string $field
583
     *
584
     * @return MappingException
585
     */
586 1
    public static function illegalToManyAssociationOnMappedSuperclass($className, $field)
587
    {
588 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."'.");
589
    }
590
591
    /**
592
     * @param string $className
593
     * @param string $targetEntity
594
     * @param string $targetField
595
     *
596
     * @return MappingException
597
     */
598
    public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
599
    {
600
        return new self("It is not possible to map entity '".$className."' with a composite primary key ".
601
            "as part of the primary key of another entity '".$targetEntity."#".$targetField."'.");
602
    }
603
604
    /**
605
     * @param string $className
606
     * @param string $field
607
     *
608
     * @return MappingException
609
     */
610
    public static function noSingleAssociationJoinColumnFound($className, $field)
611
    {
612
        return new self("'$className#$field' is not an association with a single join column.");
613
    }
614
615
    /**
616
     * @param string $className
617
     * @param string $column
618
     *
619
     * @return MappingException
620
     */
621
    public static function noFieldNameFoundForColumn($className, $column)
622
    {
623
        return new self("Cannot find a field on '$className' that is mapped to column '$column'. Either the ".
624
            "field does not exist or an association exists but it has multiple join columns.");
625
    }
626
627
    /**
628
     * @param string $className
629
     * @param string $field
630
     *
631
     * @return MappingException
632
     */
633 1
    public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
634
    {
635 1
        return new self("The orphan removal option is not allowed on an association that is ".
636 1
            "part of the identifier in '$className#$field'.");
637
    }
638
639
    /**
640
     * @param string $className
641
     * @param string $field
642
     *
643
     * @return MappingException
644
     */
645 1
    public static function illegalOrphanRemoval($className, $field)
646
    {
647 1
        return new self("Orphan removal is only allowed on one-to-one and one-to-many ".
648 1
            "associations, but " . $className."#" .$field . " is not.");
649
    }
650
651
    /**
652
     * @param string $className
653
     * @param string $field
654
     *
655
     * @return MappingException
656
     */
657 2
    public static function illegalInverseIdentifierAssociation($className, $field)
658
    {
659 2
        return new self("An inverse association is not allowed to be identifier in '$className#$field'.");
660
    }
661
662
    /**
663
     * @param string $className
664
     * @param string $field
665
     *
666
     * @return MappingException
667
     */
668 3
    public static function illegalToManyIdentifierAssociation($className, $field)
669
    {
670 3
        return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
671
    }
672
673
    /**
674
     * @param string $className
675
     *
676
     * @return MappingException
677
     */
678 1
    public static function noInheritanceOnMappedSuperClass($className)
679
    {
680 1
        return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'.");
681
    }
682
683
    /**
684
     * @param string $className
685
     * @param string $rootClassName
686
     *
687
     * @return MappingException
688
     */
689 1
    public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
690
    {
691 1
        return new self(
692 1
            "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
693 1
            "to be properly mapped in the inheritance hierarchy. Alternatively you can make '".$className."' an abstract class " .
694 1
            "to avoid this exception from occurring."
695
        );
696
    }
697
698
    /**
699
     * @param string $className
700
     * @param string $methodName
701
     *
702
     * @return MappingException
703
     */
704 1
    public static function lifecycleCallbackMethodNotFound($className, $methodName)
705
    {
706 1
        return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
707
    }
708
709
    /**
710
     * @param string $listenerName
711
     * @param string $className
712
     *
713
     * @return \Doctrine\ORM\Mapping\MappingException
714
     */
715 1
    public static function entityListenerClassNotFound($listenerName, $className)
716
    {
717 1
        return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className));
718
    }
719
720
    /**
721
     * @param string $listenerName
722
     * @param string $methodName
723
     * @param string $className
724
     *
725
     * @return \Doctrine\ORM\Mapping\MappingException
726
     */
727 1
    public static function entityListenerMethodNotFound($listenerName, $methodName, $className)
728
    {
729 1
        return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName));
730
    }
731
732
    /**
733
     * @param string $listenerName
734
     * @param string $methodName
735
     * @param string $className
736
     *
737
     * @return \Doctrine\ORM\Mapping\MappingException
738
     */
739 1
    public static function duplicateEntityListener($listenerName, $methodName, $className)
740
    {
741 1
        return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className));
742
    }
743
744
    /**
745
     * @param string $className
746
     * @param string $annotation
747
     *
748
     * @return MappingException
749
     */
750
    public static function invalidFetchMode($className, $annotation)
751
    {
752
        return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
753
    }
754
755
    /**
756
     * @param string $className
757
     *
758
     * @return MappingException
759
     */
760
    public static function compositeKeyAssignedIdGeneratorRequired($className)
761
    {
762
        return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
763
    }
764
765
    /**
766
     * @param string $targetEntity
767
     * @param string $sourceEntity
768
     * @param string $associationName
769
     *
770
     * @return MappingException
771
     */
772 1
    public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
773
    {
774 1
        return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
775
    }
776
777
    /**
778
     * @param array  $cascades
779
     * @param string $className
780
     * @param string $propertyName
781
     *
782
     * @return MappingException
783
     */
784
    public static function invalidCascadeOption(array $cascades, $className, $propertyName)
785
    {
786
        $cascades = implode(", ", array_map(function ($e) { return "'" . $e . "'"; }, $cascades));
787
788 1
        return new self(sprintf(
789 1
            "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'",
790 1
            $className,
791 1
            $propertyName,
792 1
            $cascades
793
        ));
794
    }
795
796
    /**
797
     * @param string $className
798
     *
799
     * @return MappingException
800
     */
801 1
    public static function missingSequenceName($className)
802
    {
803 1
        return new self(
804 1
            sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className)
805
        );
806
    }
807
808
    /**
809
     * @param string $className
810
     * @param string $propertyName
811
     *
812
     * @return MappingException
813
     */
814 2
    public static function infiniteEmbeddableNesting($className, $propertyName)
815
    {
816 2
        return new self(
817 2
            sprintf(
818
                'Infinite nesting detected for embedded property %s::%s. ' .
819 2
                'You cannot embed an embeddable from the same type inside an embeddable.',
820 2
                $className,
821 2
                $propertyName
822
            )
823
        );
824
    }
825
826
    /**
827
     * @param LibXMLError[] $errors
828
     */
829
    public static function fromLibXmlErrors(array $errors) : self
830
    {
831 1
        $formatter = function (LibXMLError $error): string {
832 1
            return sprintf(
833 1
                'libxml error: %s%s:%d',
834 1
                $error->message,
835 1
                $error->file,
836 1
                $error->line
837
            );
838 1
        };
839
840 1
        return new self(implode(PHP_EOL, array_map($formatter, $errors)));
841
    }
842
}
843