From 4fc86294145cd0447660b057f274f73ab95346c3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 29 Feb 2024 16:47:35 +0100 Subject: [PATCH] PHPStan 1.10.59 (#11320) --- composer.json | 2 +- phpstan-baseline.neon | 16 +++------------- src/Mapping/DefaultTypedFieldMapper.php | 10 ++++++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index ee4f1f0bc08..108d37fdc5c 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "doctrine/annotations": "^1.13 || ^2", "doctrine/coding-standard": "^9.0.2 || ^12.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.10.35", + "phpstan/phpstan": "~1.4.10 || 1.10.59", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.2", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 52bb9d5a437..c33099dee7a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -231,7 +231,7 @@ parameters: path: src/Mapping/Driver/XmlDriver.php - - message: "#^Offset 'version' on \\*NEVER\\* in isset\\(\\) always exists and is always null\\.$#" + message: "#^Offset 'version' on \\*NEVER\\* in isset\\(\\) always exists and is not nullable\\.$#" count: 1 path: src/Mapping/Driver/XmlDriver.php @@ -326,7 +326,7 @@ parameters: path: src/Query/AST/Functions/DateSubFunction.php - - message: "#^Method Doctrine\\\\ORM\\\\Query\\\\AST\\\\IndexBy\\:\\:dispatch\\(\\) should return string but returns void\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\Query\\\\AST\\\\IndexBy\\:\\:dispatch\\(\\) should return string but returns null\\.$#" count: 1 path: src/Query/AST/IndexBy.php @@ -375,11 +375,6 @@ parameters: count: 1 path: src/Query/Expr/Select.php - - - message: "#^Comparison operation \"\\<\" between null and 102 is always true\\.$#" - count: 1 - path: src/Query/Parser.php - - message: "#^Method Doctrine\\\\ORM\\\\Query\\\\Parser\\:\\:ArithmeticFactor\\(\\) should return Doctrine\\\\ORM\\\\Query\\\\AST\\\\ArithmeticFactor but returns Doctrine\\\\ORM\\\\Query\\\\AST\\\\Node\\|string\\.$#" count: 1 @@ -395,14 +390,9 @@ parameters: count: 1 path: src/Query/Parser.php - - - message: "#^Result of && is always true\\.$#" - count: 1 - path: src/Query/Parser.php - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 4 + count: 3 path: src/Query/Parser.php - diff --git a/src/Mapping/DefaultTypedFieldMapper.php b/src/Mapping/DefaultTypedFieldMapper.php index 7e57a4798cd..db7737f58e4 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; use const PHP_VERSION_ID; @@ -54,18 +56,18 @@ public function validateAndComplete(array $mapping, ReflectionProperty $field): && ($type instanceof ReflectionNamedType) ) { if (PHP_VERSION_ID >= 80100 && ! $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); }