@@ -153,6 +153,10 @@ private function convertOrderByToLatest(MethodCall $methodCall): MethodCall
153
153
return $ methodCall ;
154
154
}
155
155
156
+ if (isset ($ methodCall ->args [1 ]) && (! $ methodCall ->args [1 ] instanceof Arg || ! $ methodCall ->args [1 ]->value instanceof String_)) {
157
+ return $ methodCall ;
158
+ }
159
+
156
160
if (isset ($ methodCall ->args [1 ]) && $ methodCall ->args [1 ] instanceof Arg && $ methodCall ->args [1 ]->value instanceof String_) {
157
161
$ direction = $ methodCall ->args [1 ]->value ->value ;
158
162
} else {
@@ -164,22 +168,22 @@ private function convertOrderByToLatest(MethodCall $methodCall): MethodCall
164
168
} else {
165
169
$ newMethod = $ direction === 'asc ' ? 'oldest ' : 'latest ' ;
166
170
}
167
- if ($ columnVar instanceof String_ && $ columnVar ->value === 'created_at ' ) {
168
- $ methodCall ->name = new Identifier ($ newMethod );
169
- $ methodCall ->args = [];
170
-
171
- return $ methodCall ;
172
- }
173
171
174
- if ($ columnVar instanceof String_) {
175
- $ methodCall ->name = new Identifier ($ newMethod );
176
- $ methodCall ->args = [new Arg (new String_ ($ columnVar ->value ))];
172
+ return $ this ->createMethodCall ($ methodCall , $ newMethod , $ columnVar );
173
+ }
177
174
178
- return $ methodCall ;
175
+ private function createMethodCall (MethodCall $ methodCall , string $ newMethod , Expr $ expr ): MethodCall
176
+ {
177
+ if ($ expr instanceof String_ && $ expr ->value === 'created_at ' ) {
178
+ $ args = [];
179
+ } elseif ($ expr instanceof String_) {
180
+ $ args = [new Arg (new String_ ($ expr ->value ))];
181
+ } else {
182
+ $ args = [new Arg ($ expr )];
179
183
}
180
184
181
185
$ methodCall ->name = new Identifier ($ newMethod );
182
- $ methodCall ->args = [ new Arg ( $ columnVar )] ;
186
+ $ methodCall ->args = $ args ;
183
187
184
188
return $ methodCall ;
185
189
}
0 commit comments