33
44namespace TheCodingMachine \ClassExplorer \Glob ;
55
6+ use SplFileInfo ;
7+ use function array_keys ;
68use function chdir ;
79use DirectoryIterator ;
810use GlobIterator ;
@@ -66,14 +68,24 @@ public function __construct(string $namespace, CacheInterface $cache, ?int $cach
6668 /**
6769 * Returns an array of fully qualified class names.
6870 *
69- * @return string[]
71+ * @return array<int, string>
7072 */
7173 public function getClasses (): array
74+ {
75+ return array_keys ($ this ->getClassMap ());
76+ }
77+
78+ /**
79+ * Returns an array mapping the fully qualified class name to the file path.
80+ *
81+ * @return array<string,SplFileInfo>
82+ */
83+ public function getClassMap (): array
7284 {
7385 $ key = 'globClassExplorer_ ' .str_replace ('\\' , '_ ' , $ this ->namespace );
7486 $ classes = $ this ->cache ->get ($ key );
7587 if ($ classes === null ) {
76- $ classes = $ this ->doGetClasses ();
88+ $ classes = $ this ->doGetClassMap ();
7789 $ this ->cache ->set ($ key , $ classes , $ this ->cacheTtl );
7890 }
7991 return $ classes ;
@@ -82,9 +94,9 @@ public function getClasses(): array
8294 /**
8395 * Returns an array of fully qualified class names, without the cache.
8496 *
85- * @return string[]
97+ * @return array< string,SplFileInfo>
8698 */
87- private function doGetClasses (): array
99+ private function doGetClassMap (): array
88100 {
89101 $ namespace = trim ($ this ->namespace , '\\' ).'\\' ;
90102 if ($ this ->classNameMapper === null ) {
@@ -103,7 +115,7 @@ private function doGetClasses(): array
103115 foreach ($ filesForDir as $ file ) {
104116 // Trim the root directory name and the PHP extension
105117 $ fileTrimPrefixSuffix = \substr ($ file , $ dirLen , -4 );
106- $ classes [] = $ namespace .\str_replace ('/ ' , '\\' , $ fileTrimPrefixSuffix );
118+ $ classes [$ namespace .\str_replace ('/ ' , '\\' , $ fileTrimPrefixSuffix )] = $ file ;
107119 }
108120 }
109121 chdir ($ oldCwd );
@@ -112,7 +124,7 @@ private function doGetClasses(): array
112124
113125 /**
114126 * @param string $directory
115- * @return \Iterator
127+ * @return \Iterator<SplFileInfo>
116128 */
117129 private function getPhpFilesForDir (string $ directory ): \Iterator
118130 {
0 commit comments