diff --git a/composer.json b/composer.json index 2a002989c21..c65c03b959d 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "require-dev": { "doctrine/coding-standard": "^12.0", "phpbench/phpbench": "^1.0", - "phpstan/phpstan": "1.10.35", + "phpstan/phpstan": "1.10.59", "phpunit/phpunit": "^10.4.0", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.2", diff --git a/phpstan.neon b/phpstan.neon index 93e3875d269..4ea0a3630a2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -30,7 +30,7 @@ parameters: message: '~^Result of method Doctrine\\DBAL\\Connection::commit\(\) \(void\) is used\.$~' path: src/UnitOfWork.php - - message: '~^Strict comparison using === between void and false will always evaluate to false\.$~' + message: '~^Strict comparison using === between null and false will always evaluate to false\.$~' path: src/UnitOfWork.php - message: '~^Variable \$e on left side of \?\? always exists and is not nullable\.$~' diff --git a/src/Mapping/DefaultTypedFieldMapper.php b/src/Mapping/DefaultTypedFieldMapper.php index e83cc9ea47c..49144b8b7c8 100644 --- a/src/Mapping/DefaultTypedFieldMapper.php +++ b/src/Mapping/DefaultTypedFieldMapper.php @@ -4,6 +4,7 @@ namespace Doctrine\ORM\Mapping; +use BackedEnum; use DateInterval; use DateTime; use DateTimeImmutable; @@ -16,6 +17,7 @@ use function array_merge; use function assert; use function enum_exists; +use function is_a; /** @psalm-type ScalarName = 'array'|'bool'|'float'|'int'|'string' */ final class DefaultTypedFieldMapper implements TypedFieldMapper @@ -52,18 +54,18 @@ public function validateAndComplete(array $mapping, ReflectionProperty $field): && ($type instanceof ReflectionNamedType) ) { if (! $type->isBuiltin() && enum_exists($type->getName())) { - $mapping['enumType'] = $type->getName(); - $reflection = new ReflectionEnum($type->getName()); if (! $reflection->isBacked()) { throw MappingException::backedEnumTypeRequired( $field->class, $mapping['fieldName'], - $mapping['enumType'], + $type->getName(), ); } - $type = $reflection->getBackingType(); + assert(is_a($type->getName(), BackedEnum::class, true)); + $mapping['enumType'] = $type->getName(); + $type = $reflection->getBackingType(); assert($type instanceof ReflectionNamedType); }