@@ -353,29 +353,31 @@ function (Server $server, $msg) {
353
353
'get_composer_packages ' ,
354
354
$ accepted_process_types ,
355
355
function (Server $ server , $ msg ) {
356
+ if (!class_exists (\Composer \InstalledVersions::class)) {
357
+ return self ::json ('require composer 2.0 ' , 4003 );
358
+ }
359
+
356
360
$ list = [];
357
- if (class_exists (\Composer \InstalledVersions::class)) {
358
- foreach (['getAllRawData ' , 'getRawData ' ] as $ method ) {
359
- if (method_exists (\Composer \InstalledVersions::class, $ method )) {
360
- if ($ method === 'getAllRawData ' ) {
361
- $ raw_data = \Composer \InstalledVersions::$ method ();
362
- array_shift ($ raw_data );
363
- } else {
364
- $ raw_data [] = \Composer \InstalledVersions::$ method ();
365
- }
366
- foreach ($ raw_data as $ key => $ package ) {
367
- $ key_name = $ package ['root ' ]['name ' ];
368
- if ($ package ['root ' ]['name ' ] === '__root__ ' && isset ($ list ['__root__ ' ])) {
369
- $ key_name = "__root__ {$ key }" ;
370
- }
371
- $ package ['root ' ]['install_path ' ] = realpath ($ package ['root ' ]['install_path ' ]);
372
- $ list [$ key_name ] = $ package ;
373
- }
374
- break ;
361
+ foreach (['getAllRawData ' , 'getRawData ' ] as $ method ) {
362
+ if (!method_exists (\Composer \InstalledVersions::class, $ method )) {
363
+ continue ;
364
+ }
365
+
366
+ $ raw_data [] = \Composer \InstalledVersions::$ method ();
367
+ if ($ method === 'getAllRawData ' ) {
368
+ $ raw_data = \Composer \InstalledVersions::$ method ();
369
+ array_shift ($ raw_data );
370
+ }
371
+
372
+ foreach ($ raw_data as $ key => $ package ) {
373
+ $ key_name = $ package ['root ' ]['name ' ];
374
+ if ($ package ['root ' ]['name ' ] === '__root__ ' && isset ($ list ['__root__ ' ])) {
375
+ $ key_name = "__root__ {$ key }" ;
375
376
}
377
+ $ package ['root ' ]['install_path ' ] = realpath ($ package ['root ' ]['install_path ' ]);
378
+ $ list [$ key_name ] = $ package ;
376
379
}
377
- } else {
378
- return self ::json ('require composer 2.0 ' , 4003 );
380
+ break ;
379
381
}
380
382
return self ::json ($ list );
381
383
}
0 commit comments