@@ -37,7 +37,7 @@ public function encode(mixed $value): stdClass
3737 return match ($ value ::ENCODE ) {
3838 Encode::Single => $ this ->encodeAsSingle ($ value ),
3939 Encode::Array => $ this ->encodeAsArray ($ value ),
40- Encode::Object, Encode::FlatObject => $ this ->encodeAsObject ($ value ),
40+ Encode::Object => $ this ->encodeAsObject ($ value ),
4141 default => throw new LogicException (sprintf ('Class "%s" does not have a valid ENCODE constant. ' , $ value ::class)),
4242 };
4343 }
@@ -89,9 +89,7 @@ private function encodeAsObject(OperatorInterface $value): stdClass
8989 }
9090 }
9191
92- return $ value ::ENCODE === Encode::FlatObject
93- ? $ result
94- : $ this ->wrap ($ value , $ result );
92+ return $ this ->wrap ($ value , $ result );
9593 }
9694
9795 /**
@@ -108,10 +106,19 @@ private function encodeAsSingle(OperatorInterface $value): stdClass
108106 throw new LogicException (sprintf ('Class "%s" does not have a single property. ' , $ value ::class));
109107 }
110108
109+ /**
110+ * Wrap the result in an object if the operator has a name.
111+ * The operator name is NULL, and the result is returned as is
112+ * when wrapObject is false in the YAML configuration of the operator.
113+ */
111114 private function wrap (OperatorInterface $ value , mixed $ result ): stdClass
112115 {
116+ if ($ value ::NAME === null ) {
117+ return $ result ;
118+ }
119+
113120 $ object = new stdClass ();
114- $ object ->{$ value-> getOperator () } = $ result ;
121+ $ object ->{$ value:: NAME } = $ result ;
115122
116123 return $ object ;
117124 }
0 commit comments