<commit_before><?php

namespace sndsgd\util;

use \Exception;


/**
 * Temp file and directory utility methods
 */
class Temp
{
   /**
    * All created paths are added here for easy removal at script exit
    * 
    * @var array.<string => boolean|null>
    */
   private static $files = [];

   /**
    * Register a temp path to be deleted when the script exists
    * 
    * @param string $path An absolute path
    * @param boolean|null $isDir Whether or not $path is a directory
    */
   public static function registerPath($path, $isDir = null)
   {
      if (count(self::$files) === 0) {
         register_shutdown_function('sndsgd\\util\\Temp::cleanup');
      }
      self::$files[$path] = $isDir;
   }

   /**
    * Create a temp file
    * 
    * @param string $prefix A prefix for the file name
    * @param string|null $contents Optional contents for the file
    * @return string The path to the newly created temp file
    */
   public static function file($prefix = 'temp-', $contents = null) 
   {
      $path = tempnam(sys_get_temp_dir(), $prefix);
      if ($contents) {
         file_put_contents($path, $contents);
      }
      self::registerPath($path, false);
      return $path;
   }

   /**
    * Create a temp directory
    * 
    * @param string $prefix A prefix for the directory name
    * @return string The path to the newly created temp directory
    */
   public static function dir($prefix = 'temp')
   {
      $tmpdir = sys_get_temp_dir();
      do {
         $rand = substr(md5(microtime(true)), 0, 6);
         $path = $tmpdir.DIRECTORY_SEPARATOR.$prefix.$rand;
      }
      while (@mkdir($path) === false);
<commit_msg>added optional permission to Temp::dir<commit_after><?php

namespace sndsgd\util;

use \Exception;


/**
 * Temp file and directory utility methods
 */
class Temp
{
   /**
    * All created paths are added here for easy removal at script exit
    * 
    * @var array.<string => boolean|null>
    */
   private static $files = [];

   /**
    * Register a temp path to be deleted when the script exists
    * 
    * @param string $path An absolute path
    * @param boolean|null $isDir Whether or not $path is a directory
    */
   public static function registerPath($path, $isDir = null)
   {
      if (count(self::$files) === 0) {
         register_shutdown_function('sndsgd\\util\\Temp::cleanup');
      }
      self::$files[$path] = $isDir;
   }

   /**
    * Create a temp file
    * 
    * @param string $prefix A prefix for the file name
    * @param string|null $contents Optional contents for the file
    * @return string The path to the newly created temp file
    */
   public static function file($prefix = 'temp-', $contents = null) 
   {
      $path = tempnam(sys_get_temp_dir(), $prefix);
      if ($contents) {
         file_put_contents($path, $contents);
      }
      self::registerPath($path, false);
      return $path;
   }

   /**
    * Create a temp directory
    * 
    * @param string $prefix A prefix for the directory name
    * @param octal $mode The permissions for the directory
    * @return string The path to the newly created temp directory
    */
   public static function dir($prefix = 'temp', $mode = 0775)
   {
      $tmpdir = sys_get_temp_dir();
      do {
         $rand = substr(md5(microtime(true)), 0, 6);
         $path = $tmpdir.DIRECTORY_SEPARATOR.$prefix.$rand;
      }
      while (@mkdir($path, $mode) === false);

{'fraction_non_alphanumeric': 0.12204379562043796, 'fraction_numerical': 0.0035036496350364962, 'mean_word_length': 2.531958762886598, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6457834', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1003, 'n_words': 333}