From ee42a5a1fa874ae88f605da1e7e142e0ee2815b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 27 Apr 2024 16:39:47 +0200 Subject: [PATCH 1/2] WIp --- .envrc | 6 +++ .gitignore | 1 + .makefile/e2e.file | 2 +- fixtures/set032-isolated-finder/expected-tree | 7 ++-- src/Console/ConsoleScoper.php | 39 +++++++++++++------ 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..a6f45bcb1 --- /dev/null +++ b/.envrc @@ -0,0 +1,6 @@ +source .composer-root-version + +export XDEBUG_MODE=off + +use nix --packages \ + gnumake diff --git a/.gitignore b/.gitignore index d14abc9e8..2bea370be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ !/bin/infection.sh !/bin/php-scoper /.box_dump/ +/.direnv/ /.php-cs-fixer.cache /.phpcs-cache /.phpunit* diff --git a/.makefile/e2e.file b/.makefile/e2e.file index d6f5e7db4..8d8fe6eb5 100644 --- a/.makefile/e2e.file +++ b/.makefile/e2e.file @@ -195,7 +195,7 @@ e2e_027: $(PHP_SCOPER_PHAR_BIN) fixtures/set027-laravel/vendor --stop-on-failure composer --working-dir=build/set027-laravel dump-autoload --no-dev - php build/set027-laravel/artisan -V > build/set027-laravel/output + NO_COLOR=1 php build/set027-laravel/artisan -V > build/set027-laravel/output diff fixtures/set027-laravel/expected-output build/set027-laravel/output .PHONY: e2e_028 diff --git a/fixtures/set032-isolated-finder/expected-tree b/fixtures/set032-isolated-finder/expected-tree index 6ca3b2e4a..e3c45045b 100644 --- a/fixtures/set032-isolated-finder/expected-tree +++ b/fixtures/set032-isolated-finder/expected-tree @@ -1,6 +1,7 @@ build/set032-isolated-finder ├── actual-tree -├── file1.php -└── file2.php +└── dir + ├── file1.php + └── file2.php -0 directories, 3 files +2 directories, 3 files diff --git a/src/Console/ConsoleScoper.php b/src/Console/ConsoleScoper.php index 1d63c6468..22ca7f4f3 100644 --- a/src/Console/ConsoleScoper.php +++ b/src/Console/ConsoleScoper.php @@ -29,6 +29,7 @@ use Webmozart\Assert\Assert; use function array_keys; use function array_map; +use function array_unique; use function array_values; use function count; use function dirname; @@ -242,17 +243,7 @@ private static function getFiles(Configuration $config, string $outputDir): arra $filesWithContent = $config->getFilesWithContents(); $excludedFilesWithContents = $config->getExcludedFilesWithContents(); - $commonDirectoryPath = Path::getLongestCommonBasePath( - ...array_map( - Path::getDirectory(...), - array_keys($filesWithContent), - ), - ...array_map( - Path::getDirectory(...), - array_keys($excludedFilesWithContents), - ), - ); - Assert::notNull($commonDirectoryPath); + $commonDirectoryPath = self::getCommonDirectoryPath($config); $mapFiles = static fn (array $inputFileTuple) => new File( Path::normalize($inputFileTuple[0]), @@ -276,6 +267,32 @@ private static function getFiles(Configuration $config, string $outputDir): arra ]; } + private static function getCommonDirectoryPath(Configuration $config): string + { + $configPath = $config->getPath(); + $filesWithContent = $config->getFilesWithContents(); + $excludedFilesWithContents = $config->getExcludedFilesWithContents(); + + $directoryPaths = [ + ...array_map( + Path::getDirectory(...), + array_keys($filesWithContent), + ), + ...array_map( + Path::getDirectory(...), + array_keys($excludedFilesWithContents), + ), + ]; + + if (null !== $configPath) { + $directoryPaths[] = $configPath; + } + + return Path::getLongestCommonBasePath( + ...array_unique($directoryPaths), + ); + } + private static function findVendorDir(array $outputFilePaths): ?string { $vendorDirsAsKeys = []; From cf0b4310bf2ac259be285bf03cf306838e92df43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 27 Apr 2024 16:56:50 +0200 Subject: [PATCH 2/2] fix --- .makefile/e2e.file | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.makefile/e2e.file b/.makefile/e2e.file index 8d8fe6eb5..d6f5e7db4 100644 --- a/.makefile/e2e.file +++ b/.makefile/e2e.file @@ -195,7 +195,7 @@ e2e_027: $(PHP_SCOPER_PHAR_BIN) fixtures/set027-laravel/vendor --stop-on-failure composer --working-dir=build/set027-laravel dump-autoload --no-dev - NO_COLOR=1 php build/set027-laravel/artisan -V > build/set027-laravel/output + php build/set027-laravel/artisan -V > build/set027-laravel/output diff fixtures/set027-laravel/expected-output build/set027-laravel/output .PHONY: e2e_028