3232use Composer \ClassMapGenerator \ClassMapGenerator ;
3333use Composer \InstalledVersions ;
3434use ReflectionClass ;
35- use ReflectionException ;
35+ use Throwable ;
3636
3737/**
3838 * @internal
3939 */
4040final readonly class LoadBricks implements BricksLoader
4141{
42- /**
43- * @throws ReflectionException
44- */
4542 public function loadInstalledBricks (): array
4643 {
4744 $ packages = array_unique (InstalledVersions::getInstalledPackagesByType (self ::PACKAGE_TYPE ));
@@ -64,12 +61,11 @@ public function loadInstalledBricks(): array
6461
6562 /**
6663 * @return ServiceRepresentation[]
67- * @throws ReflectionException
6864 */
6965 private function loadServicesOfPackage (string $ package_path ): array
7066 {
7167 $ result = [];
72- $ map = ClassMapGenerator:: createMap ($ package_path );
68+ $ map = $ this -> getClassMapForPackage ($ package_path );
7369 foreach ($ map as $ symbol => $ _path ) {
7470 $ reflection = new ReflectionClass ($ symbol );
7571
@@ -85,4 +81,22 @@ private function loadServicesOfPackage(string $package_path): array
8581
8682 return $ result ;
8783 }
84+
85+ /**
86+ * @return array<class-string, non-empty-string>
87+ */
88+ private function getClassMapForPackage (string $ package_path ): array
89+ {
90+ $ generator = new ClassMapGenerator ();
91+ $ path_to_try = ['src ' , 'include ' ];
92+ foreach ($ path_to_try as $ path ) {
93+ try {
94+ $ generator ->scanPaths ($ package_path . '/ ' . $ path );
95+ } catch (Throwable ) { // phpcs:ignore
96+ // Ignore it
97+ }
98+ }
99+
100+ return $ generator ->getClassMap ()->getMap ();
101+ }
88102}
0 commit comments