@@ -115,47 +115,49 @@ private function encodeAsGroup(OperatorInterface $value): stdClass
115
115
return $ this ->wrap ($ value , $ result );
116
116
}
117
117
118
- private function encodeAsSearch (OperatorInterface $ value ): stdClass
118
+ private function encodeAsObject (OperatorInterface $ value ): stdClass
119
119
{
120
- assert ($ value instanceof SearchStage || $ value instanceof SearchMetaStage);
121
-
122
120
$ result = new stdClass ();
123
121
foreach (get_object_vars ($ value ) as $ key => $ val ) {
124
122
// Skip optional arguments. If they have a default value, it is resolved by the server.
125
123
if ($ val === Optional::Undefined) {
126
124
continue ;
127
125
}
128
126
129
- // Merge the operator properties into the result object
130
- if ($ key === 'operator ' ) {
131
- foreach (get_object_vars ($ this ->recursiveEncode ($ val )) as $ subkey => $ subval ) {
132
- $ result ->{$ subkey } = $ subval ;
133
- }
134
-
135
- continue ;
136
- }
137
-
138
127
$ result ->{$ key } = $ this ->recursiveEncode ($ val );
139
128
}
140
129
141
- return $ this ->wrap ($ value , $ result );
130
+ return $ value ::ENCODE === Encode::FlatObject
131
+ ? $ result
132
+ : $ this ->wrap ($ value , $ result );
142
133
}
143
134
144
- private function encodeAsObject (OperatorInterface $ value ): stdClass
135
+ private function encodeAsSearch (OperatorInterface $ value ): stdClass
145
136
{
137
+ assert ($ value instanceof SearchStage || $ value instanceof SearchMetaStage);
138
+
146
139
$ result = new stdClass ();
147
140
foreach (get_object_vars ($ value ) as $ key => $ val ) {
148
141
// Skip optional arguments. If they have a default value, it is resolved by the server.
149
142
if ($ val === Optional::Undefined) {
150
143
continue ;
151
144
}
152
145
146
+ // Merge the operator properties into the result object
147
+ if ($ key === 'operator ' ) {
148
+ $ val = $ this ->recursiveEncode ($ val );
149
+ assert ($ val instanceof stdClass);
150
+ foreach (get_object_vars ($ val ) as $ subkey => $ subval ) {
151
+ $ result ->{$ subkey } = $ subval ;
152
+ }
153
+
154
+ continue ;
155
+ }
156
+
153
157
$ result ->{$ key } = $ this ->recursiveEncode ($ val );
154
158
}
155
159
156
- return $ value ::ENCODE === Encode::FlatObject
157
- ? $ result
158
- : $ this ->wrap ($ value , $ result );
160
+ return $ this ->wrap ($ value , $ result );
159
161
}
160
162
161
163
/**
0 commit comments