diff --git a/src/Box.php b/src/Box.php index 628f0d39..e81732b7 100644 --- a/src/Box.php +++ b/src/Box.php @@ -17,6 +17,7 @@ use Amp\Parallel\Worker\TaskFailureThrowable; use ArrayIterator; use BadMethodCallException; +use Closure; use Countable; use DateTimeImmutable; use Fidry\FileSystem\FS; @@ -123,7 +124,7 @@ public function endBuffering(?callable $dumpAutoload): void { Assert::true($this->buffering, 'The buffering must be started before ending it'); - $dumpAutoload ??= static fn () => null; + $completeDumpAutoload = self::createDumpAutoload($dumpAutoload); $cwd = getcwd(); $tmp = FS::makeTmpDir('box', self::class); @@ -150,11 +151,7 @@ public function endBuffering(?callable $dumpAutoload): void ); } - $dumpAutoload( - $this->scoper->getSymbolsRegistry(), - $this->scoper->getPrefix(), - $this->scoper->getExcludedFilePaths(), - ); + $completeDumpAutoload(); $unknownFiles = Finder::create() ->files() @@ -182,6 +179,22 @@ public function endBuffering(?callable $dumpAutoload): void $this->phar->stopBuffering(); } + /** + * @param null|(callable(SymbolsRegistry, string, string[]): void) $dumpAutoload + * + * @return Closure():void + */ + private function createDumpAutoload(?callable $dumpAutoload): Closure + { + return null === $dumpAutoload + ? static fn () => null + : fn () => $dumpAutoload( + $this->scoper->getSymbolsRegistry(), + $this->scoper->getPrefix(), + $this->scoper->getExcludedFilePaths(), + ); + } + /** * @param non-empty-string $normalizedVendorDir Normalized path ("/" path separator and no trailing "/") to the Composer vendor directory */