Skip to content

Commit 9ca426d

Browse files
committed
Use ReflectionEnum::isBacked
1 parent 91a10a8 commit 9ca426d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
use function strtoupper;
5252
use function trigger_deprecation;
5353

54-
use const PHP_VERSION_ID;
55-
5654
/**
5755
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
5856
* of a document and it's references.
@@ -2616,16 +2614,16 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
26162614
return $mapping;
26172615
}
26182616

2619-
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) {
2617+
if (! $type->isBuiltin() && enum_exists($type->getName())) {
26202618
$reflection = new ReflectionEnum($type->getName());
2621-
$type = $reflection->getBackingType();
26222619

2623-
if ($type === null) {
2624-
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $mapping['enumType']);
2620+
if (! $reflection->isBacked()) {
2621+
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $reflection->getName());
26252622
}
26262623

2624+
$type = $reflection->getBackingType();
26272625
assert($type instanceof ReflectionNamedType);
2628-
$mapping['enumType'] = $type->getName();
2626+
$mapping['enumType'] = $reflection->getName();
26292627
}
26302628

26312629
switch ($type->getName()) {

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ parameters:
445445
count: 1
446446
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
447447

448+
-
449+
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\:\\:validateAndCompleteTypedFieldMapping\\(\\) should return array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\} but returns array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}\\.$#"
450+
count: 1
451+
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
452+
448453
-
449454
message: "#^Parameter \\#2 \\$enumType of class Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty constructor expects class\\-string\\<BackedEnum\\>, class\\-string\\<UnitEnum\\> given\\.$#"
450455
count: 1

0 commit comments

Comments
 (0)