freeSpace = $freeSpace === null ? static fn (string $path): float|false => @disk_free_space($path) : Closure::fromCallable($freeSpace); } /** Require ceil(bytes * (1 + margin)) available bytes on an existing destination directory. */ public function check(string $directory, int $bytes): void { if ($bytes < 0) { throw new InvalidArgumentException('Payload size must be nonnegative.'); } try { $free = ($this->freeSpace)($directory); } catch (Throwable $error) { throw new ImportException('SPACE_CHECK_FAILED', 'Cannot query destination free space.', $error); } if ((!is_float($free) && !is_int($free)) || !is_finite((float) $free) || $free < 0) { throw new ImportException('SPACE_CHECK_FAILED', 'Cannot determine destination free space.'); } $required = ceil($bytes + $bytes * $this->margin); if (!is_finite($required) || $free < $required) { throw new ImportException('DISK_FULL', 'Insufficient free space including the safety margin.'); } } }