<commit_before><?php
class stash_Core
{
	public function save($file)
	{
		// Check there is an uploaded file
		if (empty($file['tmp_name']) OR ! is_uploaded_file($file['tmp_name'])) return FALSE;
		
		$dir = stash::get_directory();
		$token = stash::create_token();
		
		// Stash file
		move_uploaded_file($file['tmp_name'], $dir.$token.'_file');
		
		// Stash meta data
		unset($file['tmp_name']);
		$meta = json_encode($file);
		file_put_contents($dir.$token.'_meta', $meta);
		
		if(mt_rand(1, 100) <= Kohana::config('stash.gc_probability'))
		{
			stash::garbage_collect();
		}
		
		return $token;
	}
	
	
	public function load($token, $key = NULL)
	{
		if(stash::valid($token))
		{
			$dir = stash::get_directory();
			
			$meta = file_get_contents($dir.$token.'_meta');
			$meta = json_decode($meta, TRUE);
			
			$meta['tmp_name'] = $dir.$token.'_file';
			
			return ($key === NULL) ? $meta : $meta[$key];
		}
		else
		{
			return FALSE;
		}
	}
	
	
	public function valid($token)
	{
		if( ! is_string($token) OR strlen($token) != 64 OR ! ctype_alnum($token))
		{
			return FALSE;
		}
		else
		{
			$dir = stash::get_directory();
			return (file_exists($dir.$token.'_file') AND file_exists($dir.$token.'_meta'));
		}
	}
	
	
	protected function get_directory()
	{
		static $dir;
		
		if( ! isset($dir))
		{
			$dir = Kohana::config('stash.directory', TRUE, TRUE);
			
			if ($dir === NULL)        throw new Kohana_User_Exception('Stash Directory Not Defined', '');
			if ( ! is_dir($dir))      throw new Kohana_User_Exception('Stash Directory Does Not Exist', '');
			if ( ! is_writable($dir)) throw new Kohana_User_Exception('Stash Directory Is Not Writable', '');
		}
		
		return $dir;
	}
	
	
	protected function create_token()
	{
		// Token will always be 64 chars, as uniqid is 13 chars
		$unique_part = uniqid();
		$secure_part = text::random('alnum', 51);
		return $unique_part.$secure_part;
	}
	<commit_msg>Variable renamed for clarity<commit_after><?php
class stash_Core
{
	public function save($file)
	{
		// Check there is an uploaded file
		if (empty($file['tmp_name']) OR ! is_uploaded_file($file['tmp_name'])) return FALSE;
		
		$dir = stash::get_directory();
		$token = stash::create_token();
		
		// Stash file
		move_uploaded_file($file['tmp_name'], $dir.$token.'_file');
		
		// Stash meta data
		unset($file['tmp_name']);
		$meta = json_encode($file);
		file_put_contents($dir.$token.'_meta', $meta);
		
		if(mt_rand(1, 100) <= Kohana::config('stash.gc_probability'))
		{
			stash::garbage_collect();
		}
		
		return $token;
	}
	
	
	public function load($token, $key = NULL)
	{
		if(stash::valid($token))
		{
			$dir = stash::get_directory();
			
			$meta = file_get_contents($dir.$token.'_meta');
			$meta = json_decode($meta, TRUE);
			
			$meta['tmp_name'] = $dir.$token.'_file';
			
			return ($key === NULL) ? $meta : $meta[$key];
		}
		else
		{
			return FALSE;
		}
	}
	
	
	public function valid($token)
	{
		if( ! is_string($token) OR strlen($token) != 64 OR ! ctype_alnum($token))
		{
			return FALSE;
		}
		else
		{
			$dir = stash::get_directory();
			return (file_exists($dir.$token.'_file') AND file_exists($dir.$token.'_meta'));
		}
	}
	
	
	protected function get_directory()
	{
		static $dir;
		
		if( ! isset($dir))
		{
			$dir = Kohana::config('stash.directory', TRUE, TRUE);
			
			if ($dir === NULL)        throw new Kohana_User_Exception('Stash Directory Not Defined', '');
			if ( ! is_dir($dir))      throw new Kohana_User_Exception('Stash Directory Does Not Exist', '');
			if ( ! is_writable($dir)) throw new Kohana_User_Exception('Stash Directory Is Not Writable', '');
		}
		
		return $dir;
	}
	
	
	protected function create_token()
	{
		// Token will always be 64 chars, as uniqid is 13 chars
		$unique = uniqid();
		$hard_to_guess = text::random('alnum', 51);
		return $unique.$hard_to_guess;
	}
	
{'fraction_non_alphanumeric': 0.17208214192877566, 'fraction_numerical': 0.006238627501949571, 'mean_word_length': 3.613908872901679, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '63724', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1360, 'n_words': 289}