Skip to content

Commit 4d8cf26

Browse files
committed
Merge branch '2.15.x' into 3.0.x
* 2.15.x: Deprecate undeclared entity inheritance (doctrine#10431) Psalm 5.5.0 (doctrine#10445)
2 parents 5233a13 + 6568782 commit 4d8cf26

11 files changed

+548
-363
lines changed

UPGRADE.md

+5
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ Use `toIterable()` instead.
549549

550550
# Upgrade to 2.15
551551

552+
## Deprecated undeclared entity inheritance
553+
554+
As soon as an entity class inherits from another entity class, inheritance has to
555+
be declared by adding the appropriate configuration for the root entity.
556+
552557
## Deprecated stubs for "concrete table inheritance"
553558

554559
This third way of mapping class inheritance was never implemented. Code stubs are

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"squizlabs/php_codesniffer": "3.7.1",
4545
"symfony/cache": "^5.4 || ^6.0",
4646
"symfony/var-exporter": "^5.4 || ^6.2",
47-
"vimeo/psalm": "5.4.0"
47+
"vimeo/psalm": "5.5.0"
4848
},
4949
"suggest": {
5050
"ext-dom": "Provides support for XSD validation for XML mapping files",

lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

+12
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ protected function doLoadMetadata(
136136
}
137137

138138
if (! $class->isMappedSuperclass) {
139+
if ($rootEntityFound && $class->isInheritanceTypeNone()) {
140+
Deprecation::trigger(
141+
'doctrine/orm',
142+
'https://github.com/doctrine/orm/pull/10431',
143+
"Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared. This is a misconfiguration and will be an error in Doctrine ORM 3.0.",
144+
$class->name,
145+
end($nonSuperclassParents),
146+
);
147+
// enable this in 3.0
148+
// throw MappingException::missingInheritanceTypeDeclaration(end($nonSuperclassParents), $class->name);
149+
}
150+
139151
foreach ($class->embeddedClasses as $property => $embeddableClass) {
140152
if (isset($embeddableClass['inherited'])) {
141153
continue;

lib/Doctrine/ORM/Mapping/MappingException.php

+13
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ public static function duplicateDiscriminatorEntry(string $className, array $ent
344344
);
345345
}
346346

347+
/**
348+
* @param class-string $rootEntityClass
349+
* @param class-string $childEntityClass
350+
*/
351+
public static function missingInheritanceTypeDeclaration(string $rootEntityClass, string $childEntityClass): self
352+
{
353+
return new self(sprintf(
354+
"Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared.",
355+
$childEntityClass,
356+
$rootEntityClass,
357+
));
358+
}
359+
347360
public static function missingDiscriminatorMap(string $className): self
348361
{
349362
return new self(sprintf(

0 commit comments

Comments
 (0)