<commit_before><?php

namespace Northstar\Auth\Repositories;

use League\OAuth2\Server\CryptKey;

use File;
use Storage;

class KeyRepository
{
    public function hasKeys() {
        return Storage::has('keys/public.key') || Storage::has('keys/private.key');
    }

    public function getPublicKey()
    {
        return $this->getFileCached('keys/public.key');
    }

    public function writePublicKey($key) {
        Storage::write('keys/public.key', $key);
    }

    public function getPrivateKey()
    {
        return $this->getFileCached('keys/private.key');
    }

    public function writePrivateKey($key) {
        Storage::write('keys/private.key', $key);
    }

    protected function getFileCached($path)
    {
        $cachedPath = storage_path('cache/'. $path);

        // If this isn't cached locally, fetch it from storage driver.
        if (! file_exists($cachedPath)) {
            if (! file_exists(storage_path('cache/keys'))) {
                mkdir(storage_path('cache/keys'), 0777, true);
            }
            dump(file_exists(storage_path('cache'))); //TRUE
            dump(file_exists(storage_path('cache/keys'))); //TRUE

            $key = Storage::get($path);
            file_put_contents($cachedPath, $key);
        }

        $shouldCheckPermissions = config('app.debug') === false;

        return new CryptKey('file://'.$cachedPath, null, $shouldCheckPermissions);
    }
}
<commit_msg>Clean up<commit_after><?php

namespace Northstar\Auth\Repositories;

use League\OAuth2\Server\CryptKey;

use Storage;

class KeyRepository
{
    public function hasKeys() {
        return Storage::has('keys/public.key') || Storage::has('keys/private.key');
    }

    public function getPublicKey()
    {
        return $this->getFileCached('keys/public.key');
    }

    public function writePublicKey($key) {
        Storage::write('keys/public.key', $key);
    }

    public function getPrivateKey()
    {
        return $this->getFileCached('keys/private.key');
    }

    public function writePrivateKey($key) {
        Storage::write('keys/private.key', $key);
    }

    protected function getFileCached($path)
    {
        $cachedPath = storage_path('cache/'. $path);

        // If this isn't cached locally, fetch it from storage driver.
        if (! file_exists($cachedPath)) {
            if (! file_exists(storage_path('cache/keys'))) {
                mkdir(storage_path('cache/keys'), 0777, true);
            }

            $key = Storage::get($path);
            file_put_contents($cachedPath, $key);
        }

        $shouldCheckPermissions = config('app.debug') === false;

        return new CryptKey('file://'.$cachedPath, null, $shouldCheckPermissions);
    }
}

{'fraction_non_alphanumeric': 0.1456953642384106, 'fraction_numerical': 0.003679175864606328, 'mean_word_length': 2.679296346414073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3855116', 'n_tokens_mistral': 812, 'n_tokens_neox': 785, 'n_words': 147}