@@ -291,54 +291,55 @@ impl Composer {
291291 let mut paths = vec ! [ ] ;
292292
293293 for section in & [ "autoload" , "autoload-dev" ] {
294- if let Some ( autoload) = composer_json. get ( section) {
295- for key in & [ "psr-4" , "psr-0" ] {
296- if let Some ( mappings) = autoload. get ( key) . and_then ( |v| v. as_object ( ) ) {
297- for ( _, path_value) in mappings {
298- match path_value {
299- Value :: String ( s) if !s. is_empty ( ) => {
300- paths. push ( s. trim_end_matches ( '/' ) . to_string ( ) ) ;
301- }
302- Value :: Array ( arr) => {
303- for v in arr {
304- if let Some ( s) = v. as_str ( ) {
305- if !s. is_empty ( ) {
306- paths. push (
307- s. trim_end_matches ( '/' ) . to_string ( ) ,
308- ) ;
309- }
310- }
311- }
312- }
313- _ => { }
314- }
315- }
316- }
317- }
294+ let Some ( autoload) = composer_json. get ( section) else {
295+ continue ;
296+ } ;
318297
319- if let Some ( classmap) = autoload. get ( "classmap" ) . and_then ( |v| v. as_array ( ) ) {
320- for v in classmap {
321- if let Some ( s) = v. as_str ( ) {
322- if !s. is_empty ( ) {
323- paths. push ( s. trim_end_matches ( '/' ) . to_string ( ) ) ;
324- }
325- }
298+ for key in & [ "psr-4" , "psr-0" ] {
299+ if let Some ( mappings) = autoload. get ( key) . and_then ( |v| v. as_object ( ) ) {
300+ for ( _, path_value) in mappings {
301+ Self :: collect_psr_paths ( path_value, & mut paths) ;
326302 }
327303 }
304+ }
328305
329- if let Some ( files) = autoload. get ( "files" ) . and_then ( |v| v. as_array ( ) ) {
330- for v in files {
331- if let Some ( s) = v. as_str ( ) {
332- if !s. is_empty ( ) {
333- paths. push ( s. to_string ( ) ) ;
334- }
335- }
336- }
306+ Self :: collect_string_array_paths ( autoload. get ( "classmap" ) , true , & mut paths) ;
307+ Self :: collect_string_array_paths ( autoload. get ( "files" ) , false , & mut paths) ;
308+ }
309+
310+ paths
311+ }
312+
313+ fn collect_psr_paths ( path_value : & Value , paths : & mut Vec < String > ) {
314+ match path_value {
315+ Value :: String ( s) if !s. is_empty ( ) => {
316+ paths. push ( s. trim_end_matches ( '/' ) . to_string ( ) ) ;
317+ }
318+ Value :: Array ( arr) => {
319+ for s in arr. iter ( ) . filter_map ( |v| v. as_str ( ) ) . filter ( |s| !s. is_empty ( ) ) {
320+ paths. push ( s. trim_end_matches ( '/' ) . to_string ( ) ) ;
337321 }
338322 }
323+ _ => { }
339324 }
325+ }
340326
341- paths
327+ fn collect_string_array_paths (
328+ value : Option < & Value > ,
329+ trim_trailing_slash : bool ,
330+ paths : & mut Vec < String > ,
331+ ) {
332+ let Some ( arr) = value. and_then ( |v| v. as_array ( ) ) else {
333+ return ;
334+ } ;
335+
336+ for s in arr. iter ( ) . filter_map ( |v| v. as_str ( ) ) . filter ( |s| !s. is_empty ( ) ) {
337+ if trim_trailing_slash {
338+ paths. push ( s. trim_end_matches ( '/' ) . to_string ( ) ) ;
339+ } else {
340+ paths. push ( s. to_string ( ) ) ;
341+ }
342+ }
342343 }
343344}
344345
0 commit comments