<commit_before><?php

namespace OneSheet;

/**
 * Class SheetFile
 *
 * @package OneSheet
 */
class SheetFile
{
    /**
     * @var resource
     */
    private $filePointer;

    /**
     * @var string
     */
    private $filePath;

    /**
     * SheetFile constructor.
     *
     * @throws \RuntimeException
     */
    public function __construct()
    {
        $this->filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(null, 1) . '.xml';
        if (!$this->filePointer = fopen($this->filePath, 'wb+')) {
            throw new \RuntimeException("Failed to create temporary file {$this->filePath}!");
        }
    }

    /**
     * @param $string
     */
    public function fwrite($string)
    {
        fwrite($this->filePointer, $string);
    }

    /**
     * @return bool
     */
    public function rewind()
    {
        return rewind($this->filePointer);
    }

    /**
     * @return string
     */
    public function getFilePath()
    {
        return $this->filePath;
    }

    /**
     * Close file pointer and delete sheet file.
     */
    public function __destruct()
    {
        if (!fclose($this->filePointer) || !unlink($this->filePath)) {
            throw new \RuntimeException('Failed to close sheetfile!');
        }
    }
}<commit_msg>(Re)added sheet file exceptions. (#23)<commit_after><?php

namespace OneSheet;

/**
 * Class SheetFile, just to abstract file operations awayyy.
 *
 * @package OneSheet
 */
class SheetFile
{
    /**
     * @var resource
     */
    private $filePointer;

    /**
     * @var string
     */
    private $filePath;

    /**
     * SheetFile constructor.
     *
     * @throws \RuntimeException
     */
    public function __construct()
    {
        $this->filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(null, 1) . '.xml';
        if (!$this->filePointer = fopen($this->filePath, 'wb+')) {
            throw new \RuntimeException("Failed to create temporary sheet file {$this->filePath}!");
        }
    }

    /**
     * Write a single string.
     *
     * @param $string
     */
    public function fwrite($string)
    {
        if (false === fwrite($this->filePointer, $string)) {
            throw new \RuntimeException("Failed to write to sheet file!");
        }
    }

    /**
     * Rewind file (to write header and column widths).
     */
    public function rewind()
    {
        if (false === rewind($this->filePointer)) {
            throw new \RuntimeException("Failed to rewind sheet file!");
        }
    }

    /**
     * Return full path of the file.
     *
     * @return string
     */
    public function getFilePath()
    {
        return $this->filePath;
    }

    /**
     * Close file pointer and delete file.
     */
    public function __destruct()
    {
        if (!fclose($this->filePointer) || !unlink($this->filePath)) {
            throw new \RuntimeException('Failed to close sheet file!');
        }
    }
}
{'fraction_non_alphanumeric': 0.14023144996596323, 'fraction_numerical': 0.0013614703880190605, 'mean_word_length': 1.9243781094527364, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4409951', 'n_tokens_mistral': 882, 'n_tokens_neox': 855, 'n_words': 209}