From 530211bf150309bcab1797b8efbec0bead80bfb8 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 15:23:56 +0200 Subject: [PATCH 1/4] Prevent property hooks from being used as they currently would work on external non-raw values without explicit code. --- src/Mapping/ClassMetadataInfo.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Mapping/ClassMetadataInfo.php b/src/Mapping/ClassMetadataInfo.php index 3780a5d44af..9a99f8b32e8 100644 --- a/src/Mapping/ClassMetadataInfo.php +++ b/src/Mapping/ClassMetadataInfo.php @@ -3879,7 +3879,7 @@ private function assertMappingOrderBy(array $mapping): void private function getAccessibleProperty(ReflectionService $reflService, string $class, string $field): ?ReflectionProperty { $reflectionProperty = $reflService->getAccessibleProperty($class, $field); - if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) { + if ($reflectionProperty !== null && \PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) { $declaringClass = $reflectionProperty->class; if ($declaringClass !== $class) { $reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field); @@ -3890,6 +3890,10 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c } } + if (\PHP_VERSION_ID >= 80400 && count($reflectionProperty->getHooks()) > 0) { + throw new LogicException("Doctrine ORM does not support property hooks in this version. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks."); + } + return $reflectionProperty; } } From 049886f74ee92ed4099618ec920bc67a9f170f85 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 15:32:24 +0200 Subject: [PATCH 2/4] phpcs --- src/Mapping/ClassMetadataInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mapping/ClassMetadataInfo.php b/src/Mapping/ClassMetadataInfo.php index 9a99f8b32e8..d35ce2849ad 100644 --- a/src/Mapping/ClassMetadataInfo.php +++ b/src/Mapping/ClassMetadataInfo.php @@ -3879,7 +3879,7 @@ private function assertMappingOrderBy(array $mapping): void private function getAccessibleProperty(ReflectionService $reflService, string $class, string $field): ?ReflectionProperty { $reflectionProperty = $reflService->getAccessibleProperty($class, $field); - if ($reflectionProperty !== null && \PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) { + if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) { $declaringClass = $reflectionProperty->class; if ($declaringClass !== $class) { $reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field); @@ -3890,8 +3890,8 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c } } - if (\PHP_VERSION_ID >= 80400 && count($reflectionProperty->getHooks()) > 0) { - throw new LogicException("Doctrine ORM does not support property hooks in this version. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks."); + if (PHP_VERSION_ID >= 80400 && count($reflectionProperty->getHooks()) > 0) { + throw new LogicException('Doctrine ORM does not support property hooks in this version. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks.'); } return $reflectionProperty; From 6d2f44d8317a495474b6759cdb76046cd4ddce04 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 15:57:23 +0200 Subject: [PATCH 3/4] static analysis --- phpstan-baseline.neon | 5 +++++ psalm-baseline.xml | 3 +++ src/Mapping/ClassMetadataInfo.php | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6f0a73dd5a3..3905f4fc1fe 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -165,6 +165,11 @@ parameters: count: 2 path: src/Mapping/ClassMetadataFactory.php + - + message: "#^Call to an undefined method ReflectionProperty\\:\\:getHooks\\(\\)\\.$#" + count: 1 + path: src/Mapping/ClassMetadataInfo.php + - message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\NamingStrategy\\:\\:joinColumnName\\(\\) invoked with 2 parameters, 1 required\\.$#" count: 2 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b9473bebb66..0d2d23f6ae7 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -713,6 +713,9 @@ + + + diff --git a/src/Mapping/ClassMetadataInfo.php b/src/Mapping/ClassMetadataInfo.php index d35ce2849ad..12637f2275a 100644 --- a/src/Mapping/ClassMetadataInfo.php +++ b/src/Mapping/ClassMetadataInfo.php @@ -3890,7 +3890,7 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c } } - if (PHP_VERSION_ID >= 80400 && count($reflectionProperty->getHooks()) > 0) { + if (PHP_VERSION_ID >= 80400 && $reflectionProperty !== NULL && count($reflectionProperty->getHooks()) > 0) { throw new LogicException('Doctrine ORM does not support property hooks in this version. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks.'); } From 1f25750ab6ee69d036c1e5ef38616368a4f9af04 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 16:00:29 +0200 Subject: [PATCH 4/4] phpcs --- src/Mapping/ClassMetadataInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mapping/ClassMetadataInfo.php b/src/Mapping/ClassMetadataInfo.php index 12637f2275a..881fabe28db 100644 --- a/src/Mapping/ClassMetadataInfo.php +++ b/src/Mapping/ClassMetadataInfo.php @@ -3890,7 +3890,7 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c } } - if (PHP_VERSION_ID >= 80400 && $reflectionProperty !== NULL && count($reflectionProperty->getHooks()) > 0) { + if (PHP_VERSION_ID >= 80400 && $reflectionProperty !== null && count($reflectionProperty->getHooks()) > 0) { throw new LogicException('Doctrine ORM does not support property hooks in this version. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks.'); }