2929use Webmozart \Assert \Assert ;
3030use function array_keys ;
3131use function array_map ;
32+ use function array_unique ;
3233use function array_values ;
3334use function count ;
3435use function dirname ;
@@ -242,17 +243,7 @@ private static function getFiles(Configuration $config, string $outputDir): arra
242243 $ filesWithContent = $ config ->getFilesWithContents ();
243244 $ excludedFilesWithContents = $ config ->getExcludedFilesWithContents ();
244245
245- $ commonDirectoryPath = Path::getLongestCommonBasePath (
246- ...array_map (
247- Path::getDirectory (...),
248- array_keys ($ filesWithContent ),
249- ),
250- ...array_map (
251- Path::getDirectory (...),
252- array_keys ($ excludedFilesWithContents ),
253- ),
254- );
255- Assert::notNull ($ commonDirectoryPath );
246+ $ commonDirectoryPath = self ::getCommonDirectoryPath ($ config );
256247
257248 $ mapFiles = static fn (array $ inputFileTuple ) => new File (
258249 Path::normalize ($ inputFileTuple [0 ]),
@@ -276,6 +267,28 @@ private static function getFiles(Configuration $config, string $outputDir): arra
276267 ];
277268 }
278269
270+ private static function getCommonDirectoryPath (Configuration $ config ): string
271+ {
272+ $ filesWithContent = $ config ->getFilesWithContents ();
273+ $ excludedFilesWithContents = $ config ->getExcludedFilesWithContents ();
274+
275+ $ directoryPaths = [
276+ ...array_map (
277+ Path::getDirectory (...),
278+ array_keys ($ filesWithContent ),
279+ ),
280+ ...array_map (
281+ Path::getDirectory (...),
282+ array_keys ($ excludedFilesWithContents ),
283+ ),
284+ ];
285+
286+ $ commonPath = Path::getLongestCommonBasePath (...array_unique ($ directoryPaths ));
287+ Assert::notNull ($ commonPath , 'Expected to find a common path. ' );
288+
289+ return $ commonPath ;
290+ }
291+
279292 private static function findVendorDir (array $ outputFilePaths ): ?string
280293 {
281294 $ vendorDirsAsKeys = [];
0 commit comments