<commit_before><?php

namespace JamesMoss\Flywheel;

class Repository
{
    protected $name;

    public function __construct(Config $config, $name)
    {
        $this->validateName($name);
        $this->name = $name;
        $this->path = $config->getPath() . '/' . $name;

        // ensure directory exists and we can write there
        if(!file_exists($this->path)) {
            mkdir($this->path);
            chmod($this->path, 0777);
        } 
    }

    public function getName()
    {
        return $this->name;
    }

    public function findAll()
    {
        $files     = glob($this->path . '/*.json') or array();
        $documents = array();
        
        foreach ($files as $file) {
            $documents[] = new Document(json_decode(file_get_contents($file)));
        }

        return $documents;
    }

    protected function validateName($name)
    {
        if(!preg_match('/^[0-9A-Za-z\_\-]{1,63}$/', $name)) {
            throw new \Exception(sprintf('`%s` is not a valid repository name.', $name));
        }

        return true;
    }

    public function store(Document $document)
    {
        if(!isset($document->id)) {
            $document->id = $this->generateID();
        }

        $path = $this->getPath($document->id);
        $data = json_encode((array)$document, JSON_PRETTY_PRINT);

        return file_put_contents($path, $data);
    }

    public function delete($id)
    {
        $path = $this->getPath($id);
        unlink($path);
    }

    public function getPath($id)
    {
        return $this->path . '/' . $this->getFilename($id);
    }

    public function getFilename($id)
    {
        return $id . '_' . sha1($id) . '.json';
    }

    protected function generateID()
    {
        //openssl_random_pseudo_bytes
        $num = str_replace(' ', '', microtime());
        $id  = gmp_strval(gmp_init($num, 10), 62);

        return $id;
    }


}<commit_msg>Removing json pretty print if it doesnt exist.<commit_after><?php

namespace JamesMoss\Flywheel;

class Repository
{
    protected $name;

    public function __construct(Config $config, $name)
    {
        $this->validateName($name);
        $this->name = $name;
        $this->path = $config->getPath() . '/' . $name;

        // ensure directory exists and we can write there
        if(!file_exists($this->path)) {
            mkdir($this->path);
            chmod($this->path, 0777);
        } 
    }

    public function getName()
    {
        return $this->name;
    }

    public function findAll()
    {
        $files     = glob($this->path . '/*.json') or array();
        $documents = array();
        
        foreach ($files as $file) {
            $documents[] = new Document(json_decode(file_get_contents($file)));
        }

        return $documents;
    }

    protected function validateName($name)
    {
        if(!preg_match('/^[0-9A-Za-z\_\-]{1,63}$/', $name)) {
            throw new \Exception(sprintf('`%s` is not a valid repository name.', $name));
        }

        return true;
    }

    public function store(Document $document)
    {
        if(!isset($document->id)) {
            $document->id = $this->generateID();
        }

        $path    = $this->getPath($document->id);
        $options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null;
        $data    = json_encode((array)$document, $options);

        return file_put_contents($path, $data);
    }

    public function delete($id)
    {
        $path = $this->getPath($id);
        unlink($path);
    }

    public function getPath($id)
    {
        return $this->path . '/' . $this->getFilename($id);
    }

    public function getFilename($id)
    {
        return $id . '_' . sha1($id) . '.json';
    }

    protected function generateID()
    {
        //openssl_random_pseudo_bytes
        $num = str_replace(' ', '', microtime());
        $id  = gmp_strval(gmp_init($num, 10), 62);

        return $id;
    }


}
{'fraction_non_alphanumeric': 0.15924050632911393, 'fraction_numerical': 0.007088607594936709, 'mean_word_length': 1.9931818181818182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1351231', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1202, 'n_words': 247}