@@ -102,10 +102,6 @@ public function encode($value): stdClass|array|string
102
102
throw new LogicException (sprintf ('Class "%s" does not implement OperatorInterface. ' , $ value ::class));
103
103
}
104
104
105
- if ($ value instanceof BackedEnum) {
106
- return $ this ->encodeAsEnum ($ value );
107
- }
108
-
109
105
// The generic but incomplete encoding code
110
106
switch ($ value ::ENCODE ) {
111
107
case Encode::Single:
@@ -129,21 +125,15 @@ public function encode($value): stdClass|array|string
129
125
throw new LogicException (sprintf ('Class "%s" does not have a valid ENCODE constant. ' , $ value ::class));
130
126
}
131
127
132
- private function encodeAsEnum (OperatorInterface &BackedEnum $ value ): stdClass
133
- {
134
- $ val = $ value ->value ;
135
- if ($ value ::ENCODE === Encode::Array) {
136
- $ val = [$ val ];
137
- }
138
-
139
- return $ this ->wrap ($ value , $ val );
140
- }
141
-
142
128
/**
143
129
* Encode the value as an array of properties, in the order they are defined in the class.
144
130
*/
145
131
private function encodeAsArray (OperatorInterface $ value ): stdClass
146
132
{
133
+ if ($ value instanceof BackedEnum) {
134
+ return $ this ->wrap ($ value , [$ value ->value ]);
135
+ }
136
+
147
137
$ result = [];
148
138
/** @var mixed $val */
149
139
foreach (get_object_vars ($ value ) as $ val ) {
@@ -221,6 +211,10 @@ private function encodeAsDollarObject(OperatorInterface $value): stdClass
221
211
*/
222
212
private function encodeAsSingle (OperatorInterface $ value ): stdClass
223
213
{
214
+ if ($ value instanceof BackedEnum) {
215
+ return $ this ->wrap ($ value , $ value ->value );
216
+ }
217
+
224
218
foreach (get_object_vars ($ value ) as $ val ) {
225
219
$ result = $ this ->recursiveEncode ($ val );
226
220
0 commit comments