29
29
use Webmozart \Assert \Assert ;
30
30
use function array_keys ;
31
31
use function array_map ;
32
+ use function array_unique ;
32
33
use function array_values ;
33
34
use function count ;
34
35
use function dirname ;
@@ -242,17 +243,7 @@ private static function getFiles(Configuration $config, string $outputDir): arra
242
243
$ filesWithContent = $ config ->getFilesWithContents ();
243
244
$ excludedFilesWithContents = $ config ->getExcludedFilesWithContents ();
244
245
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 );
256
247
257
248
$ mapFiles = static fn (array $ inputFileTuple ) => new File (
258
249
Path::normalize ($ inputFileTuple [0 ]),
@@ -276,6 +267,28 @@ private static function getFiles(Configuration $config, string $outputDir): arra
276
267
];
277
268
}
278
269
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
+
279
292
private static function findVendorDir (array $ outputFilePaths ): ?string
280
293
{
281
294
$ vendorDirsAsKeys = [];
0 commit comments