From 152df5435b0cf3e049915fc25a1d90013dd3874f Mon Sep 17 00:00:00 2001 From: Ruud Seberechts Date: Wed, 7 May 2025 17:39:53 +0200 Subject: [PATCH] [PropertyAccess] Improve PropertyAccessor::setValue param docs Added param-out for the $objectOrArray argument so static code analysis does not assume the passed object can change type or become an array --- src/Symfony/Component/PropertyAccess/PropertyAccessor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 9a2c82d0dcf61..8685407861ed1 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -109,6 +109,11 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa return $propertyValues[\count($propertyValues) - 1][self::VALUE]; } + /** + * @template T of object|array + * @param T $objectOrArray + * @param-out ($objectOrArray is array ? array : T) $objectOrArray + */ public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void { if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {