From a385054d7017220e2344fc1266efd0e0181bec99 Mon Sep 17 00:00:00 2001 From: Matei Stanca Date: Wed, 15 Oct 2025 15:21:53 -0400 Subject: [PATCH 1/2] AbstractEntity::build(): Fix \stdClass as array type errors. --- src/Entity/AbstractEntity.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index 035e034..ac7bb54 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -58,8 +58,31 @@ public function build(array $parameters): void foreach ($parameters as $property => $value) { $property = static::convertToCamelCase($property); - if (\property_exists($this, $property)) { + if (!\property_exists($this, $property)) { + continue; + } + + try { + $this->$property = $value; + + } catch (\Error $error) { + + // If the reason for the error was attempting to set a \stdClass + // instance to an array property, try to type cast it to an + // array ourselves. + + $reflectedProperty = new \ReflectionProperty($this, $property); + + if ( + $reflectedProperty->getType()->getName() !== 'array' || + !($value instanceof \stdClass) + ) { + continue; + } + + $this->$property = (array) $value; + } } } From 60528c1893f4c6b96975f5b9e2df68bfa1c7b094 Mon Sep 17 00:00:00 2001 From: Matei Stanca Date: Wed, 15 Oct 2025 15:46:27 -0400 Subject: [PATCH 2/2] Fix code style from commit a385054d7017220e2344fc1266efd0e0181bec99 --- src/Entity/AbstractEntity.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index ac7bb54..a940a1b 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -63,11 +63,8 @@ public function build(array $parameters): void } try { - $this->$property = $value; - } catch (\Error $error) { - // If the reason for the error was attempting to set a \stdClass // instance to an array property, try to type cast it to an // array ourselves. @@ -75,14 +72,13 @@ public function build(array $parameters): void $reflectedProperty = new \ReflectionProperty($this, $property); if ( - $reflectedProperty->getType()->getName() !== 'array' || + 'array' !== $reflectedProperty->getType()->getName() || !($value instanceof \stdClass) ) { continue; } $this->$property = (array) $value; - } } }