From 6848b947b7fa1d295337fe93a98ee3850fa85367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 3 Dec 2024 10:14:51 +0100 Subject: [PATCH] wrapObject=false is only for encode object --- generator/src/Definition/OperatorDefinition.php | 4 ++++ psalm-baseline.xml | 6 ------ src/Builder/Encoder/OperatorEncoder.php | 8 +++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/generator/src/Definition/OperatorDefinition.php b/generator/src/Definition/OperatorDefinition.php index 93174b64f..ea2873538 100644 --- a/generator/src/Definition/OperatorDefinition.php +++ b/generator/src/Definition/OperatorDefinition.php @@ -43,6 +43,10 @@ public function __construct( default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)), }; + if (!$wrapObject && $this->encode !== Encode::Object) { + throw new UnexpectedValueException(sprintf('Operator "%s" cannot have wrapObject set to false when encode is not "object"', $name)); + } + // Convert arguments to ArgumentDefinition objects // Optional arguments must be after required arguments $requiredArgs = $optionalArgs = []; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2f361193f..301c049ac 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -75,12 +75,6 @@ - - - - - - diff --git a/src/Builder/Encoder/OperatorEncoder.php b/src/Builder/Encoder/OperatorEncoder.php index 8c45d628a..09c23ab83 100644 --- a/src/Builder/Encoder/OperatorEncoder.php +++ b/src/Builder/Encoder/OperatorEncoder.php @@ -89,6 +89,10 @@ private function encodeAsObject(OperatorInterface $value): stdClass } } + if ($value::NAME === null) { + return $result; + } + return $this->wrap($value, $result); } @@ -113,9 +117,7 @@ private function encodeAsSingle(OperatorInterface $value): stdClass */ private function wrap(OperatorInterface $value, mixed $result): stdClass { - if ($value::NAME === null) { - return $result; - } + assert(is_string($value::NAME)); $object = new stdClass(); $object->{$value::NAME} = $result;