88use Phauthentic \CognitiveCodeAnalysis \Business \Cognitive \Events \ParserFailed ;
99use Phauthentic \CognitiveCodeAnalysis \Business \Cognitive \Events \SourceFilesFound ;
1010use Phauthentic \CognitiveCodeAnalysis \Business \Utility \DirectoryScanner ;
11+ use Phauthentic \CognitiveCodeAnalysis \Business \Utility \FilenameNormalizer ;
1112use Phauthentic \CognitiveCodeAnalysis \CognitiveAnalysisException ;
1213use Phauthentic \CognitiveCodeAnalysis \Config \CognitiveConfig ;
1314use Phauthentic \CognitiveCodeAnalysis \Config \ConfigService ;
@@ -118,7 +119,7 @@ private function findMetrics(iterable $files): CognitiveMetricsCollection
118119 $ metricsCollection = $ this ->processMethodMetrics (
119120 $ metrics ,
120121 $ metricsCollection ,
121- $ this -> normalizeFilename ($ file )
122+ FilenameNormalizer:: normalize ($ file )
122123 );
123124 }
124125
@@ -141,10 +142,8 @@ private function processMethodMetrics(
141142 continue ;
142143 }
143144
144-
145145 [$ class , $ method ] = explode (':: ' , $ classAndMethod );
146146
147-
148147 $ metricsArray = array_merge ($ metrics , [
149148 'class ' => $ class ,
150149 'method ' => $ method ,
@@ -192,26 +191,6 @@ private function findSourceFiles(string $path, array $exclude = []): iterable
192191 );
193192 }
194193
195- /**
196- * Get the project root directory path.
197- *
198- * Start from the current file's directory and traverse up to find composer.json
199- *
200- * @return string|null The project root path or null if not found
201- */
202- private function getProjectRoot (): ?string
203- {
204- $ currentDir = __DIR__ ;
205-
206- while ($ currentDir !== dirname ($ currentDir )) {
207- if (file_exists ($ currentDir . DIRECTORY_SEPARATOR . 'composer.json ' )) {
208- return $ currentDir ;
209- }
210- $ currentDir = dirname ($ currentDir );
211- }
212-
213- return null ;
214- }
215194
216195 /**
217196 * Generate a cache key for a file based on path, modification time, and config hash
@@ -260,27 +239,6 @@ public function clearCache(): void
260239 $ this ->cachePool ->clear ();
261240 }
262241
263- /**
264- * Normalize filename for the test environment
265- *
266- * This is to ensure consistent file paths in test outputs
267- */
268- private function normalizeFilename (SplFileInfo $ file ): string
269- {
270- $ filename = $ file ->getRealPath ();
271-
272- if (getenv ('APP_ENV ' ) !== 'test ' ) {
273- return $ filename ;
274- }
275-
276- $ projectRoot = $ this ->getProjectRoot ();
277- if ($ projectRoot && str_starts_with ($ filename , $ projectRoot )) {
278- $ filename = substr ($ filename , strlen ($ projectRoot ) + 1 );
279- }
280-
281- return $ filename ;
282- }
283-
284242 /**
285243 * Try to get cached metrics for a file
286244 *
0 commit comments