diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 902b0ec7..4497e6df 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -265,7 +265,10 @@ private function retrieveExcludedFiles(string $dirPath, array $config): array $file = $dirPath.DIRECTORY_SEPARATOR.$file; } - $excludedFiles[$index] = realpath($file); + unset( $excludedFiles[$index] ); + $fileKey = str_replace( $dirPath.DIRECTORY_SEPARATOR, '', $file ); + $file = realpath($file); + $excludedFiles[$fileKey] = $file; } // We ignore files not found excluded file as we do not want to bail out just because a file we do not want to @@ -353,7 +356,7 @@ private static function retrieveFilesWithContents(iterable $files): array { $filesWithContents = []; - foreach ($files as $filePathOrFileInfo) { + foreach ($files as $fileKey => $filePathOrFileInfo) { $filePath = $filePathOrFileInfo instanceof SplFileInfo ? $filePathOrFileInfo->getRealPath() : realpath($filePathOrFileInfo); @@ -366,7 +369,7 @@ private static function retrieveFilesWithContents(iterable $files): array throw InvalidConfigurationValue::forUnreadableFile($filePath); } - $filesWithContents[$filePath] = [$filePath, file_get_contents($filePath)]; + $filesWithContents[$fileKey] = [$filePath, file_get_contents($filePath)]; } return $filesWithContents; diff --git a/src/Console/ConsoleScoper.php b/src/Console/ConsoleScoper.php index ed237d5b..70b0bfb1 100644 --- a/src/Console/ConsoleScoper.php +++ b/src/Console/ConsoleScoper.php @@ -255,10 +255,10 @@ private static function getFiles(Configuration $config, string $outputDir): arra $commonDirectoryPath = self::getCommonDirectoryPath($config); - $mapFiles = static fn (array $inputFileTuple) => new File( + $mapFiles = static fn (array $inputFileTuple, string $fileKey ) => new File( Path::normalize($inputFileTuple[0]), $inputFileTuple[1], - $outputDir.str_replace($commonDirectoryPath, '', Path::normalize($inputFileTuple[0])), + $outputDir.str_replace($commonDirectoryPath, '', Path::normalize($fileKey)), ); return [ @@ -266,13 +266,15 @@ private static function getFiles(Configuration $config, string $outputDir): arra array_map( $mapFiles, $filesWithContent, - ), + array_keys( $filesWithContent ) + ) ), array_values( array_map( $mapFiles, $excludedFilesWithContents, - ), + array_keys( $excludedFilesWithContents ) + ) ), ]; }