Skip to content

Commit 13765fb

Browse files
authored
refactor: Simplify the dump autoload call (#1543)
1 parent c7dfc0b commit 13765fb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Box.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Amp\Parallel\Worker\TaskFailureThrowable;
1818
use ArrayIterator;
1919
use BadMethodCallException;
20+
use Closure;
2021
use Countable;
2122
use DateTimeImmutable;
2223
use Fidry\FileSystem\FS;
@@ -127,7 +128,7 @@ public function endBuffering(?callable $dumpAutoload): void
127128
{
128129
Assert::true($this->buffering, 'The buffering must be started before ending it');
129130

130-
$dumpAutoload ??= static fn () => null;
131+
$completeDumpAutoload = self::createDumpAutoload($dumpAutoload);
131132
$cwd = getcwd();
132133

133134
$tmp = FS::makeTmpDir('box', self::class);
@@ -156,11 +157,7 @@ public function endBuffering(?callable $dumpAutoload): void
156157
);
157158
}
158159

159-
$dumpAutoload(
160-
$this->scoper->getSymbolsRegistry(),
161-
$this->scoper->getPrefix(),
162-
$this->scoper->getExcludedFilePaths(),
163-
);
160+
$completeDumpAutoload();
164161

165162
$unknownFiles = fromPairs(
166163
map(
@@ -191,6 +188,22 @@ public function endBuffering(?callable $dumpAutoload): void
191188
$this->phar->stopBuffering();
192189
}
193190

191+
/**
192+
* @param null|(callable(SymbolsRegistry, string, string[]): void) $dumpAutoload
193+
*
194+
* @return Closure():void
195+
*/
196+
private function createDumpAutoload(?callable $dumpAutoload): Closure
197+
{
198+
return null === $dumpAutoload
199+
? static fn () => null
200+
: fn () => $dumpAutoload(
201+
$this->scoper->getSymbolsRegistry(),
202+
$this->scoper->getPrefix(),
203+
$this->scoper->getExcludedFilePaths(),
204+
);
205+
}
206+
194207
/**
195208
* @param non-empty-string $normalizedVendorDir Normalized path ("/" path separator and no trailing "/") to the Composer vendor directory
196209
*/

0 commit comments

Comments
 (0)