Could you move this code for getting folders as an array into a separate method with appropriate extend hooks to make it easier to write unit tests for and other services to modify / extend (e.g subsite module may want to modify this source list).