src/fs/Temp.php
public static function createFile(
        string $name,
        int $maxAttempts = 10
    ): entity\FileEntity
    {
        $tmpdir = static::getDir();
        $name = \sndsgd\Fs::sanitizeName($name);
        $pos = strrpos($name, ".");
        if ($pos === false) {
            $extension = "";
        } else {
            $extension = substr($name, $pos);
            $name = substr($name, 0, $pos);
        }

        $attempts = 1;
        do {
            if ($attempts > $maxAttempts) {
                throw new \RuntimeException(
                    "failed to create temp file; ".
                    "reached max number ($maxAttempts) of attempts"
                );
            }
            $rand = \sndsgd\Str::random(10);
            $path = "$tmpdir/$name-$rand$extension";
            $attempts++;
        }
        while (file_exists($path));
        touch($path);
        $file = new entity\FileEntity($path);
        static::registerEntity($file);
        return $file;
    }
public static function createFile(
        string $name,
        int $maxAttempts = 10
    ): entity\FileEntity
    {
        $tmpdir = static::getDir();
        $name = \sndsgd\Fs::sanitizeName($name);
        $pos = strrpos($name, ".");
        if ($pos === false) {
            $extension = "";
        } else {
            $extension = substr($name, $pos);
            $name = substr($name, 0, $pos);
        }

        $attempts = 1;
        do {
            if ($attempts > $maxAttempts) {
                throw new \RuntimeException(
                    "failed to create temp file; ".
                    "reached max number ($maxAttempts) of attempts"
                );
            }
            $rand = \sndsgd\Str::random(10);
            $path = "$tmpdir/$name-$rand$extension";
            $attempts++;
        }
        while (file_exists($path));
        touch($path);
        $file = new entity\FileEntity($path);
        static::registerEntity($file);
        return $file;
    }
Create a temp file

@param string $name The name to use in the temp file
@param int $maxAttempts The max number of times to attempt the create
@return \sndsgd\fs\entity\FileEntity